Files
Failed to load latest commit information.
sdk-templates
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||
# {{projectName}} JavaScript client for the [UCL API](https://uclapi.com). See the main UCL API Documentation at <https://uclapi.com/docs>. This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - API version: {{appVersion}} - Package version: {{projectVersion}} {{^hideGenerationTimestamp}} - Build date: {{generatedDate}} {{/hideGenerationTimestamp}} - Build package: {{generatorClass}} ## Installation ### For [Node.js](https://nodejs.org/) #### npm Install the SDK through [npm](https://www.npmjs.com/) via: ```shell npm install {{{projectName}}} --save ``` ### git If you want to use the SDK via this GitHub repository, then install it via: ```shell npm install uclapi/uclapi-js-sdk --save ``` ### For browser The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following the above steps with Node.js and installing browserify with `npm install -g browserify`, perform the following (assuming *index.js* is your entry file, that's to say your JavaScript file where you actually use this library): ```shell browserify index.js > bundle.js ``` Then include *bundle.js* in your HTML pages. ### Webpack Configuration Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config: ```javascript module: { rules: [ { parser: { amd: false } } ] } ``` ## Getting Started Please follow the [installation](#installation) instruction and execute the following JS code: ```javascript const {{{moduleName}}} = require('{{{projectName}}}'); {{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} {{#hasAuthMethods}} const defaultClient = {{{moduleName}}}.ApiClient.instance; {{#authMethods}} {{#isBasic}} {{#isBasicBasic}} // Configure HTTP basic authorization: {{{name}}} const {{{name}}} = defaultClient.authentications['{{{name}}}']; {{{name}}}.username = 'YOUR USERNAME' {{{name}}}.password = 'YOUR PASSWORD' {{/isBasicBasic}} {{#isBasicBearer}} // Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}} const {{{name}}} = defaultClient.authentications['{{{name}}}']; {{{name}}}.accessToken = "YOUR ACCESS TOKEN" {{/isBasicBearer}} {{/isBasic}} {{#isApiKey}} // Configure API key authorization: {{{name}}} const {{{name}}} = defaultClient.authentications['{{{name}}}']; {{{name}}}.apiKey = "YOUR API KEY" // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //{{{name}}}.apiKeyPrefix['{{{keyParamName}}}'] = "Token" {{/isApiKey}} {{#isOAuth}} // Configure OAuth2 access token for authorization: {{{name}}} const {{{name}}} = defaultClient.authentications['{{{name}}}']; {{{name}}}.accessToken = "YOUR ACCESS TOKEN" {{/isOAuth}} {{/authMethods}} {{/hasAuthMethods}} const api = new {{{moduleName}}}.{{{classname}}}() {{#hasParams}} {{#requiredParams}} const {{{paramName}}} = {{{example}}}; // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}} {{/requiredParams}} {{#optionalParams}} {{#-first}} const opts = { {{/-first}} '{{{paramName}}}': {{{example}}}{{^-last}},{{/-last}} // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}} {{#-last}} }; {{/-last}} {{/optionalParams}} {{/hasParams}} {{#usePromises}} api.{{{operationId}}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}).then(function({{#returnType}}data{{/returnType}}) { {{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}} }, function(error) { console.error(error); }); {{/usePromises}}{{^usePromises}} const callback = function(error, data, response) { if (error) { console.error(error); } else { {{#returnType}}console.log('API called successfully. Returned data: ', data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}} } }; api.{{{operationId}}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}{{#hasParams}}, {{/hasParams}}callback); {{/usePromises}}{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} ``` See more detailed examples at the [`uclapi-openapi`](https://github.com/uclapi/uclapi-openapi/examples) repository. ## Documentation for API Endpoints All URIs are relative to *{{basePath}}* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{moduleName}}.{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} ## Documentation for Models {{#models}}{{#model}} - [{{moduleName}}.{{classname}}]({{modelDocPath}}{{classname}}.md) {{/model}}{{/models}} ## Documentation for Authorization {{^authMethods}} All endpoints do not require authorization. {{/authMethods}} {{#authMethods}} {{#last}} Authentication schemes defined for the API:{{/last}} ### {{name}} {{#isApiKey}} - **Type**: API key - **API key parameter name**: {{keyParamName}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} {{#isBasic}} {{#isBasicBasic}} - **Type**: HTTP basic authentication {{/isBasicBasic}} {{#isBasicBearer}} - **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} - **Type**: OAuth - **Flow**: {{flow}} - **Authorization URL**: {{authorizationUrl}} - **Scopes**: {{^scopes}}N/A{{/scopes}} {{#scopes}} - {{scope}}: {{description}} {{/scopes}} {{/isOAuth}} {{/authMethods}}