Skip to content

ngnono/ngnono-web-client-g

Repository files navigation

ngnono-web-client-g NPM version Build Status Dependency Status

Installation

$ npm install --save ngnono-web-client-g

Usage

    var ngnonoWebClient = require('ngnono-web-client-g');

配置

    let setting = {
    consumerKey: 'xxxxdefault'
    secretKey: '998998'
    baseUrl: 'http://192.168.18.31:8080/api'
    };

    let route = {
    'sign.testGet': {
        uri: '/sign/testGet',
        method: 'GET',
        json: true
    },
    'sign.testPost': {
        uri: '/sign/testPost',
        method: 'POST',
        json: true
    },
    'upload.upload': {
        uri: '/upload/upload',
        method: 'POST'
    },
    'upload.upload1': {
        uri: '/upload/upload1',
        method: 'POST'
    }
    };

GET

            

            var p = gsbClient.sign.testGet({
                qs: {
                    a: 1,
                    b: 'adadf'
                },
                headers: {
                    'X-Token': 'sxxxx'
                }
            });

            p.then(function (body) {
                //console.log('body:%s', JSON.stringify(body));
                expect(body).to.not.equal(null);
                expect(body).to.have.property('status').that.equal(true);

                //OK
            }, function (err) {
                // reject
            }).catch(function (err) {
                //err
            });

POST

            var p = gsbClient.sign.testPost( {
                qs: {
                    a: 1,
                    b: 'adadf'
                },
                body: {
                    json: 'xxfffasdf', ppppp: 12343434,
                    xml: '没有'
                },
                headers: {
                    'X-Token': 'sxxxx'
                }
            });

            p.then(function (body) {
                //console.log('body:%s', JSON.stringify(body));
                expect(body).to.not.equal(null);
                expect(body).to.have.property('status').that.equal(true);

                //OK
            }, function (err) {
                //reject
            }).catch(function (err) {
                //error
            });

upload files

            var formData = {
                my_field: 'my_value',
                my_file: fs.createReadStream(__dirname + '/config/default.yml')
            };
            var p = gsbClient.upload.upload1({
                formData: formData,
                json: true,
                qs: {a: 'w', xy: 6, c: 5}
            });

            p.then(function (body) {
                //console.log('body:%s', JSON.stringify(body));
                expect(body).to.not.equal(null);
                expect(body).to.have.property('status').that.equal(true);

                //ok
            }, function (err) {
                //reject
            }).catch(function (err) {
                console.error(err);
                //error
            });

核心代码说明

sdk copy from li-sdk

License

Apache-2.0 © lianghongpeng

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published