Official Links SDK generated from OpenAPI Spec
npm install @devlinks/sdkOfficial TypeScript/JavaScript SDK for the Links API. This SDK is generated from Openapi Spec using OpenAPI Generator.
``bash`
npm install @links/sdkor
yarn add @links/sdkor
pnpm add @links/sdk
`typescript
const client = new LinksSDK({
accessToken: "
});
const result = await client.externalConnectionApi.getExternalConnection();
console.log("External Connection: ", result.data)
`
- accessToken - Your API key for authentication. You can get the api key from application settings on API key section.
`typescript`
const client = new LinksSDK({
accessToken: "
});
The SDK is written in TypeScript and provides full type definitions:
Best practice is to store your API key in environment variables:
`bash`.env
LINKS_API_KEY=your_api_key
`typescript
import { LinksClient } from '@links/sdk';
const client = new LinksSDK({
accessToken: process.env.LINKS_API_KEY!,
});
`
`bashInstall dependencies
npm install
$3
Exposing endpoint or API to sdk is through openapi specs in Backend epo (openapi/openapi.yaml). For every endpoint that is defined in specs will be generated into class and function.
- [Resource]API is generated from endpoint with tags. Tags on specs will be the api, and every endpoint that is using the same tags will be its method.
- operationId from the path specs will be its function that is exposed from [Resource]API class
- parameters will be parameter on the operation function
- Endpoint without tags will generated into defaultApi class#### Sample specs
`yaml
paths:
/foo:
get:
summary: Get list of foo
operationId: getFoo
tags:
- foobar
parameters:
- in: query
name: page
required: false
schema:
type: number
- in: query
name: limit
required: false
schema:
type: number
responses:
'200':
description: List of foo('s)
content:
application/json:
schema:
type: array
items:
type: string
/bar:
get:
summary: Get list of bar
operationId: getBar
tags:
- foobar
parameters:
- in: query
name: page
required: false
schema:
type: number
- in: query
name: limit
required: false
schema:
type: number
responses:
'200':
description: List of bar('s)
content:
application/json:
schema:
type: array
items:
type: string
`
#### Generated class and endpoint
`typescript
import { LinksClient } from '@links/sdk';const client = new LinksSDK({
accessToken: process.env.LINKS_API_KEY!,
});
const foos: string[] = await client.foobarApi.getFoo({
page: 1,
limit: 10
})
const bars: string[] = await client.foobarApi.getBar({
page: 1,
limit: 10
})
`
$3
API generated from openapi generator need to be updated / regenerate if openapi specs is updated.#### Requirement
- JDK11 (minimum) can be downloaded here
- Template. Can be pulled from sdk-generator-template repo, and adjust script on package.json (generate-api)
and replace with your location of sdk-generator-template on your machine
#### Step
- Run
npm run generate-api`#####
ISC
For issues and questions, please visit: https://support.links.com