JS SDK for APIs published by cortical.io
The API docs as well as a get started guide can be found on api.cortical.io.
Specifically, you can check out:
- NLP API page
- Semantic Fingerprint API page
where you will also find the API specifications.
Run
npm i @corticalio/js-sdk
in the root folder of the node project where you want to use this SDK.
Import the NlpApiEndpoints
or FpApiEndpoints
class from the npm package:
const { NlpApiEndpoints, FpApiEndpoints } = require('@corticalio/js-sdk');
Supply your API tokens (e.g. store them in an .env
file so you don't have to add them to your code):
const nlpApiEndpoints = new NlpApiEndpoints("<YOUR-NLP-API-TOKEN>");
const fpApiEndpoints = new FpApiEndpoints("<YOUR-FP-API-TOKEN>");
Use the SDK by calling the constructor of the instantiated classes. E.g.:
// sends a request to the `supported-languages` endpoint of the NLP API
const languages = await nlpApiEndpoints.getSupportedLanguages();
// sends a request to the "fingerprint" endpoint of the Semantic Fingerprint API
const payload = {
text: 'this is some example text',
};
const queryParams = {
inverse_position_weighting: true,
max_density: 0.04,
max_df: 0.2,
max_terms: 3,
pos_filter: false,
pos_weighting: false,
retina_name: 'en_retina',
stop_filter: false,
tfidf_weighting: false,
use_phrase_fingerprints: false
};
const fingerprint = await fpApiEndpoints.getFingerprint(payload, queryParams);
Once you have selected either a free plan or purchased a paid plan on the API portal associated with an API product, you can retrieve the API key via the username dropdown in the top right corner, select Apps & Subscriptions / My Apps, click on the name of the app you associated with the product and plan in the previous section. The apiKey is listed as Token ID under Access and Credentials info.
This API token can then be passed to either the constructor of the NlpApiEndpoints
or the FpApiEndpoints
class.