0.1.0 • Published 8 years ago
sr-swagger-client v0.1.0
Install dependency
npm install --save sr-swagger-client --scope=@walmartNote: You need update your ~/.npmrc to point to Walmart npm registry first.
Example
The following code shows how to call the petstore service using sr-swagger-client module.
Pre-requisite
- Registered the petstore REST service to Service Registry
appKey=SWAGGERPETSTOREenvName=dev
- Running service mesh agent (sidecar) locally at
localhost:8080
Calling REST Service
'use strict'
/*
* The <b>client</b> is an instance of Swagger
*
* see https://github.com/swagger-api/swagger-js#constructor-and-methods
*/
const client = require('sr-swagger-client');
client({
srBaseUrl: 'http://api.reg.soa.stg1.walmart.com',
appKey: 'SWAGGERPETSTORE',
envName: 'dev',
overwrites: {
host: 'localhost:8080'
}
}).then((client)=> {
console.log(client.spec);
client.apis.pet // OpenApi: tag
.addPet({body: {id: 1, name: "bobby"}}) // OpenApi: operationId
.then(res=> {
console.log(res);
}, err => {
console.log(err);
});
});Note:
- The default value of
srBaseUrlishttp://api.reg.soa.walmart.com. - The
overwriteswill overwrite the same property of the original OpenApi doc.
More about Swagger API
Since the client in above demo is an object of Swagger, please refer to the original Swagger-js for more detail.
0.1.0
8 years ago