npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rest-api-module

v1.3.4

Published

REST API framework, Simple and tiny. Return JSON for client.

Downloads

14

Readme

RESTAPI

REST API framework, Simple and tiny. Return JSON for client.

First Install the module

$ npm install rest-api-module 

then simply use it.

Usage

const {Server,Router} = require("rest-api-module");

Server.port = 3000;

Router.get("/home",(response,request)=>{
    let obj = {message:"Hello world"}
    //Body , Message, StatusCode, Code
    res.returnJson(obj,"Success",200,0);
})

Server.runServer();

Options

In the Router you can use: GET POST DELETE PUT.

AT the callback you dont have to do much you already have the Body Paramaters and the Head paramaters example:
Lets say we have POST Request:
localhost:3000/test/43?param1=1&param2=2
and in the Body Paramaters we have:
accessToken=blabla


router.get("/test/:id", (res, req) => {
    res.returnJson({
        header:res.getHeaderParams(),
        body:res.getBodyParams()
        },"Success",200,0);    
})

And in the response we will have:

{
    "code": 0,
    "data": {
        "header": {
            "routerParams": {
                "id": "43"
            },
            "otherParams": {
                "param1": "1",
                "param2": "2"
            }
        },
        "body": {
            "bodyParams": {
                "accessToken": "blabla"
            }
        }
    },
    "message": "Success"
}

That way you save time in getting all the parameters were sent.

Files

Now you can set file folders to upload to and if to save the original name of the
file, simply as that! While your uploading the files you will get the uploaded file in the
bodyParamas, you will have the full content + the "link".

Server.setFiles("uploads/",true);

Response

| method | return | example | |--- |--- |--- | | returnJson | return response object | {code:0,data:{msg:"hello"},message:"Success"} | | getBodyParams | return the body parameters |"bodyParams": {"accessToken": "blabla"} | | getHeaderParams | return the header parameters| "routerParams": {"id": "43"},"otherParamas": {"param2": "2"} |

Middlewares

All you have to do is to add middlewears as many as you want and just use them if you want

example:

 const {Server,Router} = require("rest-api-module");

Server.port = 3000;
//first you add the name of the middleware then you use the callBack function
Server.add("name",(response,request)=>{
    if(response.routerParams.name == "I am Cool"){
        return true;
    }
    return false;
});
// Assign the middlware
Router.get("/home",(response,request)=>{
    //Body , Message=null, StatusCode=200, Code=0
    response.returnJson({message:"Hello World"});
},['name']);

Server.runServer();

if the middlware passed it will continue else it will throw error that it not passed and tell you in which middlware

Good Luck and Enjoy.