Skip to content

Instantly share code, notes, and snippets.

@ponelat
Created May 3, 2015 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ponelat/b2fcea0c7921029d72dc to your computer and use it in GitHub Desktop.
Save ponelat/b2fcea0c7921029d72dc to your computer and use it in GitHub Desktop.
Basic sending of an api_key
<script src='browser/swagger-client.js' type='text/javascript'></script>
<script type="text/javascript">
// initialize swagger, point to a resource listing
window.swagger = new SwaggerClient({
url: "http://petstore.swagger.io/api/api-docs",
success: function() {
// This will add a query parameter called api_key with the value 'special-key'
this.clientAuthorizations.add("api_key", new client.ApiKeyAuthorization("api_key","special-key","query"));
// This will add a header called api_key with the value 'special-key'
this.clientAuthorizations.add("api_key", new client.ApiKeyAuthorization("api_key","special-key","header"));
// upon connect, fetch a pet and set contents to element "mydata"
swagger.apis.pet.getPetById({petId:1}, function(data) {
document.getElementById("mydata").innerHTML = JSON.stringify(data.obj);
});
}
});
</script>
<body>
<div id="mydata"></div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment