Solace Event Portal APIM OpenAPI Client for NodeJS
Warning
Experimental. Please use with care.
Requirements
node 16.x
Install
npm install @solace-labs/ep-apim-openapi-node
Configure OpenAPI Object
import { OpenAPI } from "@solace-labs/ep-apim-openapi-node";
// to use a different base url than specified in the spec:
OpenAPI.BASE = "{base-url}";
OpenAPI.WITH_CREDENTIALS = true;
OpenAPI.CREDENTIALS = "include";
OpenAPI.TOKEN = "{token}";
Example: Retrieve Event API Products
import {
EventApiProduct,
EventApiProductsResponse,
EventApiProductsService,
} from "@solace-labs/ep-apim-openapi-node";
const eventApiProductList: Array<EventApiProduct> = [];
let nextPage: number | null = 1;
while(nextPage !== null) {
const eventApiProductsResponse: EventApiProductsResponse = await EventApiProductsService.listEventApiProducts({
pageNumber: nextPage,
});
eventApiProductList.push(...eventApiProductsResponse.data);
nextPage = meta.pagination.nextPage;
}
Advanced Usage
Use of fetch-with-proxy
Node fetch replaced with fetch-with-proxy.
See node-fetch-with-proxy for details.
Use of a resolver
OpenAPIConfig:
export type OpenAPIConfig = {
BASE: string | Resolver<string>;
VERSION: string;
WITH_CREDENTIALS: boolean;
CREDENTIALS: 'include' | 'omit' | 'same-origin';
TOKEN?: string | Resolver<string>;
USERNAME?: string | Resolver<string>;
PASSWORD?: string | Resolver<string>;
HEADERS?: Headers | Resolver<Headers>;
ENCODE_PATH?: (path: string) => string;
};
Configure OpenAPI Object using a Resolver for the BASE Url:
const getBase = async(): Promise<string> => {
// set your base ...
const myBase = ..., or
const myBase = await ...
return myBase;
}
// make use of it
OpenAPI.BASE = async() => { return await getBase(); }