rastapi

0.0.6 • Public • Published

RastAPI

Fast and easy-to-use API maker made for JavaScript

Usage

Setup

  • CommonJS
require("rastapi");
  • Module
import RastAPI from "rastapi";

Create Server

  • HTTP
const server = new $rast.httpServer();
  • HTTPS
const server = new $rast.httpsServer();

Listening on port

server.listen(80).then(() => console.log("I am listening on port 80 ✨"));

Create Page

  • GET with an object
$rast.get("/");
server.json(() => {
    return {
        "message": "Hello World ✨"
    };
});
  • GET with a file
$rast.get("/myfile");
server.file(() => "./myfile.json");

Using url variables

$rast.get("/test/:test");
server.json(res => {
    return {"message": "You are in /test/" + res.getVariables().test};
});

Using url query

$rast.get("/test");
server.json(res => {
    return {"message": "You have successfully entered!", "query": res.getQuery()};
});

Not found page

$rast.notFound();
server.json(() => {
    return {"message": "Not Found 🙁"};
});

Set icon

$rast.Icon.createFromURL("https://i1.sndcdn.com/avatars-000389897325-h3s225-t500x500.jpg")
    .then(img => server.setIcon(img))
    .catch(err => console.error(err));

Package Sidebar

Install

npm i rastapi

Weekly Downloads

1

Version

0.0.6

License

MIT

Unpacked Size

15 kB

Total Files

4

Last publish

Collaborators

  • oguzhanumutlu