Created
July 9, 2013 06:52
-
-
Save fehguy/5955214 to your computer and use it in GitHub Desktop.
Calling your API in javascript with swagger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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