npm add @speakeasy-api/speakeasy-client-sdk-typescript
yarn add @speakeasy-api/speakeasy-client-sdk-typescript
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.getApis({
metadata: {
key: ["<value>"],
},
op: {
and: false,
},
});
if (res.statusCode == 200) {
// handle response
}
}
run();
- deleteApi - Delete an Api.
- generateOpenApiSpec - Generate an OpenAPI specification for a particular Api.
- generatePostmanCollection - Generate a Postman collection for a particular Api.
- getAllApiVersions - Get all Api versions for a particular ApiEndpoint.
- getApis - Get a list of Apis for a given workspace
- upsertApi - Upsert an Api
- deleteApiEndpoint - Delete an ApiEndpoint.
- findApiEndpoint - Find an ApiEndpoint via its displayName.
- generateOpenApiSpecForApiEndpoint - Generate an OpenAPI specification for a particular ApiEndpoint.
- generatePostmanCollectionForApiEndpoint - Generate a Postman collection for a particular ApiEndpoint.
- getAllApiEndpoints - Get all Api endpoints for a particular apiID.
- getAllForVersionApiEndpoints - Get all ApiEndpoints for a particular apiID and versionID.
- getApiEndpoint - Get an ApiEndpoint.
- upsertApiEndpoint - Upsert an ApiEndpoint.
- deleteVersionMetadata - Delete metadata for a particular apiID and versionID.
- getVersionMetadata - Get all metadata for a particular apiID and versionID.
- insertVersionMetadata - Insert metadata for a particular apiID and versionID.
- deleteSchema - Delete a particular schema revision for an Api.
- downloadSchema - Download the latest schema for a particular apiID.
- downloadSchemaRevision - Download a particular schema revision for an Api.
- getSchema - Get information about the latest schema.
- getSchemaDiff - Get a diff of two schema revisions for an Api.
- getSchemaRevision - Get information about a particular schema revision for an Api.
- getSchemas - Get information about all schemas associated with a particular apiID.
- registerSchema - Register a schema.
- getBlob - Get blob for a particular digest
- getManifest - Get manifest for a particular reference
- getNamespaces - Each namespace contains many revisions.
- getRevisions
- getTags
- postTags - Add tags to an existing revision
- preflight - Get access token for communicating with OCI distribution endpoints
- getAccessToken - Get or refresh an access token for the current workspace.
- getUser - Get information about the current user.
- getWorkspaceAccess - Get access allowances for a particular workspace
- validateApiKey - Validate the current api key.
- generateRequestPostmanCollection - Generate a Postman collection for a particular request.
- getRequestFromEventLog - Get information about a particular request.
- queryEventLog - Query the event log to retrieve a list of requests.
- getOrganizations - Get organizations for a user
- getChangesReportSignedUrl - Get the signed access url for the change reports for a particular document.
- getLintingReportSignedUrl - Get the signed access url for the linting reports for a particular document.
- uploadReport - Upload a report.
- getEmbedAccessToken - Get an embed access token for the current workspace.
- getValidEmbedAccessTokens - Get all valid embed access tokens for the current workspace.
- revokeEmbedAccessToken - Revoke an embed access EmbedToken.
- getWorkspaceEventsByTarget - Load recent events for a particular workspace
- getWorkspaceTargets - Load targets for a particular workspace
- postWorkspaceEvents - Post events for a specific workspace
- searchWorkspaceEvents - Search events for a particular workspace by any field
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Example
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
let res;
try {
res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
} catch (err) {
if (err instanceof errors.SDKError) {
console.error(err); // handle exception
throw err;
}
}
if (res.statusCode == 200) {
// handle response
}
}
run();
You can override the default server globally by passing a server name to the server: string
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
Name | Server | Variables |
---|---|---|
prod |
https://api.prod.speakeasyapi.dev |
None |
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
server: "prod",
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
The default server can also be overridden globally by passing a URL to the serverURL: str
optional parameter when initializing the SDK client instance. For example:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
serverURL: "https://api.prod.speakeasyapi.dev",
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
The Typescript SDK makes API calls using the axios HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom AxiosInstance
object.
For example, you could specify a header for every request that your sdk makes as follows:
import { @speakeasy-api/speakeasy-client-sdk-typescript } from "Speakeasy";
import axios from "axios";
const httpClient = axios.create({
headers: {'x-custom-header': 'someValue'}
})
const sdk = new Speakeasy({defaultClient: httpClient});
This SDK supports the following security schemes globally:
Name | Type | Scheme |
---|---|---|
apiKey |
apiKey | API key |
bearer |
http | HTTP Bearer |
You can set the security parameters through the security
optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.apis.deleteApi({
apiID: "<value>",
versionID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set workspaceID
to "<value>"
at SDK initialization and then you do not have to pass the same value on calls to operations like getWorkspaceEventsByTarget
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameter is available.
Name | Type | Required | Description |
---|---|---|---|
workspaceID | string | The workspaceID parameter. |
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.events.getWorkspaceEventsByTarget({
targetID: "<value>",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.auth.getWorkspaceAccess(
{},
{
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
}
);
if (res.statusCode == 200) {
// handle response
}
}
run();
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
async function run() {
const sdk = new Speakeasy({
retry_config: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
const res = await sdk.auth.getWorkspaceAccess({});
if (res.statusCode == 200) {
// handle response
}
}
run();