npm.io
1.0.32 • Published 2d ago

w-restapi

Licence
MIT
Version
1.0.32
Deps
3
Size
12.3 MB
Vulns
0
Weekly
0

w-restapi

A REST API server with swagger.

language npm version license npm download npm download jsdelivr download

Documentation

To view documentation or get support, visit docs.

Installation

Using npm(ES6 module):
npm i w-restapi
Example for w-restapi:

Link: [dev source code]

import WRestapi from 'w-restapi'

let routes = [
    {
        apiName: 'store',
        props: {
            'id': {
                'type': 'string',
                'description': 'id description',
            },
            'prodcname': {
                'type': 'string',
                'description': 'prodcname description',
            },
            'price': {
                'type': 'number',
                'description': 'price description',
            }
        },
    },
    {
        apiName: 'pet',
        props: {
            'id': {
                'type': 'string',
                'description': 'id description',
            },
            'petname': {
                'type': 'string',
                'description': 'petname description',
            },
            'belognname': {
                'type': 'string',
                'description': 'belognname description',
            }
        },
    },
]

function proc({ method, apiName, propName, propValue, payload, pm, req, res }) {
    //可由req內資訊做身份驗證

    //resolve
    pm.resolve(JSON.stringify({ method, apiName, propName, propValue, payload }))
    console.log(method, apiName, propName, propValue, payload)

}

new WRestapi({ routes, proc })

//view swagger: http://localhost:8080/swdoc/index.html

Keywords