@sr-sdks/api-sdk-axios
v2.6.0-pre.1
Published
OpenAPI client for @sr-sdks/api-sdk-axios
Downloads
907
Maintainers
Readme
@sr-sdks/[email protected]
This is a TypeScript/JavaScript client that utilizes axios.
It is generated from OpenAPI (Swagger) specs produced by the backend project.
It includes API classes and model interfaces compatible with the backend. The benefit of this is that the client side doesn't need to maintain matching interfaces or hand coded APIs.
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via package.json
. (Reference)
Consuming
Navigate to the folder of your consuming project and run the following command to install from the published package:
npm install @sr-sdks/[email protected] --save
APIs available
The following APIs are available:
Permissions microservice
Workspaces microservice
Payments microservice
Titles microservice
Documents microservice
Shared microservice
Example usage
You can use the SDK to make API calls to the server. For example, to get a list of users, you can use the following code:
Pre-requisites
- An axios instance. This could simply be created with
axios.create()
or something more complex with interceptors for adding request Authorization headers, caching, response handling, etc. depending on application requirements. - Define a function which will prepare an instance of the API class to be used:
import { Configuration, UsersApi } from '@sr-sdks/api-sdk-axios';
import axiosInstance from './utils/axiosInstance';
// function for creating an instance of the UsersApi class
const GetUsersApi = () => {
return new UsersApi(
new Configuration(),
process.env.REACT_APP_PERMISSIONS_API_BASE,
axiosInstance,
);
};
Example 1: Get a list of users for a workspace
Use the UsersApi class to make a call to the find all users endpoint.
import { User, UsersApi } from '@sr-sdks/api-sdk-axios';
// get the workspace id from somewhere, e.g.:
const workspaceId = 'workspace-id-from-path-params';
let users: User[];
try {
const result = await GetUsersApi().usersControllerFindAllV2(workspaceId);
users = result.data.items;
} catch (error) {
// handle error
}
Example 2: Get the current user
Use the UsersApi class to make a call to the find user me endpoint.
import { User, UsersApi } from '@sr-sdks/api-sdk-axios';
let userMe: User;
try {
const result = await GetUsersApi().usersControllerFindMe();
userMe = result.data;
} catch (error) {
// handle error
}
Example 3: Create an invitation
Use the InvitationApi class to make a call to the create invitation endpoint.
import { Configuration, CreateInvitationDto, Invitation, InvitationsApi } from '@sr-sdks/api-sdk-axios';
// function for creating an instance of the InvitationsApi class
const GetInvitationsApi = () => {
return new InvitationsApi(
new Configuration(),
process.env.REACT_APP_PERMISSIONS_API_BASE,
axiosInstance,
);
};
let invitation: Invitation;
const createInvitationDto: CreateInvitationDto = {
// properties of the invitation assembled from user-entered form data or CSV, etc.
};
try {
const result = await GetInvitationsApi().invitationControllerCreate(createInvitationDto);
invitation = result.data;
} catch (error) {
// handle error
}
Generating
Use the scripts defined in the backend project.
Building
To build and compile the typescript sources to javascript use:
npm install
npm run build
Publishing
Commit and push the code. Bitbucket Pipelines will automatically publish the package.