🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

restyts

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restyts

Lightweight small library for REST api. Have all kind of features out of the box!

1.0.25
latest
Source
npm
Version published
Weekly downloads
25
Maintainers
1
Weekly downloads
 
Created
Source

RestyTS

Lightweight small library for REST api. Have all kind of features out of the box!

Install

npm install restyts

Usage

Typescript:

import { RestyApp } from 'restyts';

const app = new RestyApp({
    logger: console,
    showRoutes: true,
    port: 8080,
    createBodyData: true,
    detectResponseTime: true
});
app.use((req: IRestyRequest, res: IRestyResponse , next: IRestyNextFunction) => {
    // Do any kind of work;
    next();
});

app.get('/:id', (req: IRestyRequest, res: IRestyResponse , next: IRestyNextFunction) => {
    console.log(req.body, req.query, req.params, req.files);
    console.log(req.currentRoute);
    res.send.OK({"isWorking": true}, "Working!");
})

app.use((req: IRestyRequest, res: IRestyResponse , next: IRestyNextFunction, err: any) => {
    // Failed, received some error;
    res.send.SERVERERROR(err);
})

app.start();

Options

OptionExplanationdefault
loggerthis property can receive any logger that have "error" and "log" functionsnone
showRoutescan have a list of all routes with their properties printed to the loggerfalse
portthe port the server will run on8000
createBodyDataparse body data, json/multipart/urlencoded with files datafalse
detectResponseTimeshow in milliseconds how much time the whole endpoint took in the loggerfalse

detectResponseTime

that how it looks when you set it up to true:

[28/5/2020 08:36:47:59]: POST /:id [STARTED]
[28/5/2020 08:36:47:65]: POST /:id [ENDED] -> took: 0.006s

Keywords

rest

FAQs

Package last updated on 17 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts