0.1.3 • Published 6 years ago

http-microservice-client v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

#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

0.1.3

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago