Hi all,
I generated a javascript api-client using swagger. The /src folder of the generated client is cotaining a index.js, which provides access to constructors for public API classes.
Now, I’m trying to use it in my javascript project and want to run the API calls on browser-site.
Inside the index.js there is a comment which describes, how to use it:
/**
* An_OpenAPI_for_EVE_Online.<br>
* The <code>index</code> module provides access to constructors for all the classes which comprise the public API.
* <p>
* An AMD (recommended!) or CommonJS application will generally do something equivalent to the following:
* <pre>
* var EveSwaggerInterface = require('index'); // See note below*.
* var xxxSvc = new EveSwaggerInterface.XxxApi(); // Allocate the API class we're going to use.
* var yyyModel = new EveSwaggerInterface.Yyy(); // Construct a model instance.
* yyyModel.someProperty = 'someValue';
* ...
* var zzz = xxxSvc.doSomething(yyyModel); // Invoke the service.
* ...
* </pre>
* <em>*NOTE: For a top-level AMD script, use require(['index'], function(){...})
* and put the application logic within the callback function.</em>
* </p>
* <p>
* A non-AMD browser application (discouraged) might do something like this:
* <pre>
* var xxxSvc = new EveSwaggerInterface.XxxApi(); // Allocate the API class we're going to use.
* var yyy = new EveSwaggerInterface.Yyy(); // Construct a model instance.
* yyyModel.someProperty = 'someValue';
* ...
* var zzz = xxxSvc.doSomething(yyyModel); // Invoke the service.
* ...
* </pre>
* </p>
However, this will not work for me. If I try to access APIs/function I’ll get reference errors (not defined).
Here is an example how I’ll use it:
//var EveSwaggerInterface = require('eve_swagger_interface'); // I'm not using NodeJs (as I'm on client-site)
var api = new EveSwaggerInterface.AllianceApi() // how I should embed the API on client-site here, as I'm not using NodeJs
var opts = {
'datasource': "tranquility", // {String} The server name you would like data from
'ifNoneMatch': "ifNoneMatch_example", // {String} ETag from a previous request. A 304 will be returned if this matches the current ETag
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
api.getAlliancesAllianceId(99000001, opts, callback);
In my html site I referenced the index.js of the API:
<script src="eve-esi-api/src/index.js"></script>
So, whats the right way to use a generated ESI client on browser site?
Thanks in advance.
BR
n2k