nexttech
6 years agoNew Contributor
Swagger JS Client example in detail
Hi all,
I started to use the Swagger JS Client (https://github.com/swagger-api/swagger-js) in my Vue.JS project to connect an OpenAPI 3.0. Anyway, is this a good approach? Or are there better solutions out there?
Now I am struggeling to pass parameters to my backend. What are the minimal lines to make an API call using swagger-js? And how can I define the method?
Swagger('https://my-api/auth/login') .then(function (swaggerClient) { console.log('Swagger then swaggerClient', swaggerClient.apis) return swaggerClient.apis.Auth.loginUser({ username: 'test', password: 'test123' }) }, function (reason) { console.error('(Swagger Client) Failed to load the spec' + reason) }) .then(function (loginUser) { console.log('Swagger then loginUser', loginUser.obj) // you may return more promises, if necessary }, function (reason) { console.error('(Swagger Client) Failed on API call ' + reason) })
The first funciton.then(function (swaggerClient) already makes an API call but without sending parameters. How can I send paramters?
I haven't found out why the second one .then(function (loginUser) is in the example. Can I remove this?
Unfortulately I haven't found a good and self-explaning example. So my question here - can someone help out?
Thx so far.