@@ -23,12 +23,12 @@ bower install swagger-js
23
23
24
24
Then let swagger do the work!
25
25
``` js
26
- var client = require (' swagger-client' );
26
+ var Swagger = require (' swagger-client' );
27
27
28
- var swagger = new client ({
28
+ var client = new Swagger ({
29
29
url: ' http://petstore.swagger.io/v2/swagger.json' ,
30
30
success : function () {
31
- swagger .pet .getPetById ({petId: 7 },{responseContentType: ' application/json' },function (pet ){
31
+ client .pet .getPetById ({petId: 7 },{responseContentType: ' application/json' },function (pet ){
32
32
console .log (' pet' , pet);
33
33
});
34
34
}
@@ -71,12 +71,12 @@ That's it! You'll get a JSON response with the default callback handler:
71
71
You need to pass success and error functions to do anything reasonable with the responses:
72
72
73
73
``` js
74
- var client = require (' swagger-client' );
74
+ var Swagger = require (' swagger-client' );
75
75
76
- var swagger = new client ({
76
+ var client = new Swagger ({
77
77
url: ' http://petstore.swagger.io/v2/swagger.json' ,
78
78
success : function () {
79
- swagger .pet .getPetById ({petId: 7 }, function (success ){
79
+ client .pet .getPetById ({petId: 7 }, function (success ){
80
80
console .log (' succeeded and returned this object: ' + success .obj );
81
81
},
82
82
function (error ) {
@@ -109,19 +109,19 @@ new Swagger({
109
109
Need to pass an API key? Configure one as a query string:
110
110
111
111
``` js
112
- client .clientAuthorizations .add (" apiKey" , new client .ApiKeyAuthorization (" api_key" ," special-key" ," query" ));
112
+ client .clientAuthorizations .add (" apiKey" , new Swagger .ApiKeyAuthorization (" api_key" ," special-key" ," query" ));
113
113
```
114
114
115
115
...or with a header:
116
116
117
117
``` js
118
- client .clientAuthorizations .add (" apiKey" , new client .ApiKeyAuthorization (" api_key" ," special-key" ," header" ));
118
+ client .clientAuthorizations .add (" apiKey" , new Swagger .ApiKeyAuthorization (" api_key" ," special-key" ," header" ));
119
119
```
120
120
121
121
...or with the swagger-client constructor:
122
122
123
123
``` js
124
- var swagger = new client ({
124
+ var client = new Swagger ({
125
125
url: ' http://example.com/spec.json' ,
126
126
success : function () {},
127
127
authorizations : {
@@ -140,12 +140,12 @@ Download `browser/swagger-client.js` into your webapp:
140
140
``` js
141
141
< script src= ' browser/swagger-client.js' type= ' text/javascript' >< / script>
142
142
< script type= " text/javascript" >
143
- // initialize swagger, point to a resource listing
144
- window .swagger = new SwaggerClient ({
143
+ // initialize swagger client , point to a resource listing
144
+ window .client = new SwaggerClient ({
145
145
url: " http://petstore.swagger.io/v2/swagger.json" ,
146
146
success : function () {
147
147
// upon connect, fetch a pet and set contents to element "mydata"
148
- swagger .pet .getPetById ({petId: 1 },{responseContentType: ' application/json' }, function (data ) {
148
+ client .pet .getPetById ({petId: 1 },{responseContentType: ' application/json' }, function (data ) {
149
149
document .getElementById (" mydata" ).innerHTML = JSON .stringify (data .obj );
150
150
});
151
151
}
@@ -163,19 +163,19 @@ var pet = {
163
163
id: 100 ,
164
164
name: " dog" };
165
165
166
- swagger .pet .addPet ({body: pet});
166
+ client .pet .addPet ({body: pet});
167
167
```
168
168
169
169
### Sending XML in as a payload to your API?
170
170
``` js
171
171
var pet = " <Pet><id>2</id><name>monster</name></Pet>" ;
172
172
173
- swagger .pet .addPet ({body: pet}, {requestContentType: " application/xml" });
173
+ client .pet .addPet ({body: pet}, {requestContentType: " application/xml" });
174
174
```
175
175
176
176
### Need XML response?
177
177
``` js
178
- swagger .pet .getPetById ({petId: 1 }, {responseContentType: " application/xml" });
178
+ client .pet .getPetById ({petId: 1 }, {responseContentType: " application/xml" });
179
179
```
180
180
181
181
### Custom request signing
0 commit comments