- Notifications
You must be signed in to change notification settings - Fork0
License
unkeyed/speakeasy
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:
- 🛠 Make your SDK feel handcrafted bycustomizing it
- ♻️ Refine your SDK quickly by iterating locally with theSpeakeasy CLI
- 🎁 Publish your SDK to package managers byconfiguring automatic publishing
- ✨ When ready to productionize, delete this section from the README
npm add<UNSET>
yarn add<UNSET>
import{SDK}from"openapi";asyncfunctionrun(){constsdk=newSDK({bearerAuth:"<YOUR_BEARER_TOKEN_HERE>",});constres=awaitsdk.getV1Liveness();if(res?.statusCode!==200){thrownewError("Unexpected status code: "+res?.statusCode||"-");}// handle response}run();
- getV1Liveness
- getV1KeysGetKey
- postV1KeysDeleteKey
- postV1KeysCreateKey
- postV1KeysVerifyKey
- postV1KeysUpdateKey
- postV1KeysUpdateRemaining
- getV1KeysGetVerifications
- getVxKeysGetVerifications
- getV1ApisGetApi
- postV1ApisCreateApi
- getV1ApisListKeys
- postV1ApisDeleteApi
- putV1KeysKeyId
- getV1KeysKeyId
- deleteV1KeysKeyId
- postV1Keys
- postV1KeysVerify
- postV1Apis
- getV1ApisApiId
- deleteV1ApisApiId
- getV1ApisApiIdKeys
All SDK methods 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.ErrBadRequest | 400 | application/json |
| errors.ErrUnauthorized | 401 | application/json |
| errors.ErrForbidden | 403 | application/json |
| errors.ErrNotFound | 404 | application/json |
| errors.ErrConflict | 409 | application/json |
| errors.ErrTooManyRequests | 429 | application/json |
| errors.ErrInternalServerError | 500 | application/json |
| errors.SDKError | 4xx-5xx | / |
Example
import{SDK}from"openapi";import*aserrorsfrom"openapi/models/errors";asyncfunctionrun(){constsdk=newSDK({bearerAuth:"<YOUR_BEARER_TOKEN_HERE>",});constres=awaitsdk.getV1Liveness().catch((err)=>{if(errinstanceoferrors.ErrBadRequest){console.error(err);// handle exceptionreturnnull;}elseif(errinstanceoferrors.ErrUnauthorized){console.error(err);// handle exceptionreturnnull;}elseif(errinstanceoferrors.ErrForbidden){console.error(err);// handle exceptionreturnnull;}elseif(errinstanceoferrors.ErrNotFound){console.error(err);// handle exceptionreturnnull;}elseif(errinstanceoferrors.ErrConflict){console.error(err);// handle exceptionreturnnull;}elseif(errinstanceoferrors.ErrTooManyRequests){console.error(err);// handle exceptionreturnnull;}elseif(errinstanceoferrors.ErrInternalServerError){console.error(err);// handle exceptionreturnnull;}else{throwerr;}});if(res?.statusCode!==200){thrownewError("Unexpected status code: "+res?.statusCode||"-");}// handle response}run();
You can override the default server globally by passing a server index to theserverIdx: number 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 indexes associated with the available servers:
| # | Server | Variables |
|---|---|---|
| 0 | https://api.unkey.dev | None |
The default server can also be overridden globally by passing a URL to theserverURL: str optional parameter when initializing the SDK client instance. For example:
The TypeScript SDK makes API calls using anHTTPClient that wraps the nativeFetch API. Thisclient is a thin wrapper aroundfetch and provides the ability to attach hooksaround the request lifecycle that can be used to modify the request or handleerrors and response.
TheHTTPClient constructor takes an optionalfetcher argument that can beused to integrate a third-party HTTP client or when writing tests to mock outthe HTTP client and feed in fixtures.
The following example shows how to use the"beforeRequest" hook to to add acustom header and a timeout to requests and how to use the"requestError" hookto log errors:
import{SDK}from"openapi";import{HTTPClient}from"openapi/lib/http";consthttpClient=newHTTPClient({// fetcher takes a function that has the same signature as native `fetch`.fetcher:(request)=>{returnfetch(request);}});httpClient.addHook("beforeRequest",(request)=>{constnextRequest=newRequest(request,{signal:request.signal||AbortSignal.timeout(5000);});nextRequest.headers.set("x-custom-header","custom value");returnnextRequest;});httpClient.addHook("requestError",(error,request)=>{console.group("Request Error");console.log("Reason:",`${error}`);console.log("Endpoint:",`${request.method}${request.url}`);console.groupEnd();});constsdk=newSDK({ httpClient});
This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
bearerAuth | http | HTTP Bearer |
To authenticate with the API thebearerAuth parameter must be set when initializing the SDK client instance. For example:
import{SDK}from"openapi";asyncfunctionrun(){constsdk=newSDK({bearerAuth:"<YOUR_BEARER_TOKEN_HERE>",});constres=awaitsdk.getV1Liveness();if(res?.statusCode!==200){thrownewError("Unexpected status code: "+res?.statusCode||"-");}// handle response}run();
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usageto a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionallylooking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically.Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!
SDK Created bySpeakeasy
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.