http-microservice-client

0.1.3 • Public • Published

#http-microservice-client

NPM version

A enjoyable http client for restfull microservice to make request to http microservice without any coding.

All http requests in json file will be generator a Promise function in this client.

Installation

Requires node v6.1.0 or higher for ES6 and generator function support.

$ npm install http-microservice-client

Example

    const config = {
        foo:{
            host:'http://localhost:8080',
            api:[
                {
                    name:'bar',
                    path:'/bar/:id',
                    headers:['Authorization']
                },
                {
                    name:'bazz',
                    path:'/bazz',
                    method:'POST'
                }
            ]
        }
    }

    const Microservice = require("http-microservice-client");
    const client = new Microservice( config );
    
    
    try {
        let barResBody = yield client.foo.bar({id:'1',Authorization:'token'})
    } catch ( e ) {
    
        let statusCode = e.code;
        let message = e.message;
        console.log(statusCode, message);
    }
    
    try {
        let bazzResBody = yield client.foo.bazz({x:1,y:2});
    } catch ( e ) {
    
        let statusCode = e.code;
        let message = e.message;
        console.log(statusCode, message);
    }

In api config default method is 'GET'.

License

MIT

Package Sidebar

Install

npm i http-microservice-client

Weekly Downloads

2

Version

0.1.3

License

MIT

Last publish

Collaborators

  • xuxiaoyu