README
apilib (v0.0.4)
This class library is meant to be used for communication with the AEMS-Main-API (TODO: Insert link once repository has been created) within JavaScript/TypeScript.
:exclamation: Version notice
As indicated by the version number, the API should not be considered stable yet.
Installation
npm install @aems/apilib --save
// Optional dependency to map JSON data to actual TypeScript objects
npm install @aems/core-classlib --save
Usage
You can use the ApiService
class to perform authentication and requests to the API. You will probably want to make it some sort of singleton in your project.
const apiService = new ApiService('http://localhost:8085'); // Replace with real API url
Before you can query stuff or insert stuff you will need to authenticate.
// Preferred:
apiService.authenticate("username", "password")
.then(token => {
console.log(`Login OK, token: ${token}`);
// do whatever you wanna do after login was successful
})
.catch((error: AxiosError) => console.log(`Login has failed!`, error.message));
// OR: Set the API token manually if you obtained it somehow
// Note that this token will not be checked for correctness or validity.
apiService.setApiToken("tokenEJP07s4R...");
Then you can use the QueryRequestBuilder
and the DmlRequestBuilder
in order to configure your requests.
const aemsQuery = `
users {
id ? between $MIN and $MAX
}
`;
const queryBuilder = new QueryRequestBuilder(aemsQuery);
queryBuilder.addPlaceholder("MIN", 0); // Placeholders in query are signified by a leading '