New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

easy-api

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-api

Super easy promise-based api declaration

Source
npmnpm
Version
0.0.7
Version published
Weekly downloads
6
-14.29%
Maintainers
1
Weekly downloads
 
Created
Source

easy-api

Super easy promise-based api declaration.

build status

Install

npm install --save easy-api

Usage

Declaring route and using handlers is super easy

Server-side

var easyApi = require('easy-api')

var app = easyApi()

app.get(
    '/some/object/:paramA/:paramB',
    function(paramA, paramB) {
        return doAnythingNotPromisified(paramA, paramB);
        // or...
        return doAnythingPromisified(paramA, paramB);
    }
)
app.post(
    '/some/object',
    function(label, content, catName) {
        return createObjectHoweverYouWant(label, content, catName);
    }
)

app.start(4567).then(function() {
    console.log('Server started')
})

Currently, the value resolved by the promise (or returned by the function) is returned using JSON.stringify.

Client-side

Using request (or request-promise)
request.get({
    url : '/some/object/valueA/valueB',
    json : true
})

request.post({
    uri: '/some/object',
    json : true,
    body : {
        label : 'cat',
        content : 'meow',
        catName : 'Isis'
    }
})
Using XMLHttpRequest
request('GET', '/some/object/valueA/valueB')
request('POST', '/some/object', {
    label : 'cat',
    content : 'meow',
    catName : 'Isis'
})

function request(type, url, content) {
    return new Promise(function(resolve, reject) {
        var req = new XMLHttpRequest()
        req.open(type.toUpperCase(), url, true)
        var params = JSON.stringify(content)

        req.setRequestHeader("Content-type", "application/json")
        req.setRequestHeader("Content-length", params.length)
        req.setRequestHeader("Connection", "close")

        req.onreadystatechange = function(aEvt) {
            if (req.readyState == 4) {
                if (req.status == 200)
                    resolve(JSON.parse(req.responseText))
                else
                    reject()
            }
        }
        req.send(params)
    })
}

Tests

npm test

build status

Keywords

easy

FAQs

Package last updated on 02 Sep 2015

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