Skip to content

Instantly share code, notes, and snippets.

@fehguy
Created July 9, 2013 06:52
Show Gist options
  • Save fehguy/5955214 to your computer and use it in GitHub Desktop.
Save fehguy/5955214 to your computer and use it in GitHub Desktop.
Calling your API in javascript with swagger
// install the swagger-client
npm install swagger-client
// start the node repl
node
> var swagger = require("swagger-client");
> var s = new swagger.SwaggerApi("http://petstore.swagger.wordnik.com/api/api-docs.json");
// build the swagger client
> s.build();
// find out about arguments
> s.apis.pet.getPetById.help();
'* petId (required) - ID of pet that needs to be fetched'
// call the api with the default (logging) callback, or provide your own
> s.apis.pet.getPetById({petId:1}, /* successCallback, errorCallback*/);
{
"id": 1,
"category": {
"id": 2,
"name": "Cats"
},
"name": "Cat 1",
"photoUrls": [
"url1",
"url2"
],
"tags": [
{
"id": 1,
"name": "tag1"
},
{
"id": 2,
"name": "tag2"
}
],
"status": "available"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment