Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

unkeyed/speakeasy

Repository files navigation

🏗Welcome to your new SDK! 🏗

It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:

SDK Installation

NPM

npm add<UNSET>

Yarn

yarn add<UNSET>

SDK Example Usage

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();

Available Resources and Operations

Error Handling

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 ObjectStatus CodeContent Type
errors.ErrBadRequest400application/json
errors.ErrUnauthorized401application/json
errors.ErrForbidden403application/json
errors.ErrNotFound404application/json
errors.ErrConflict409application/json
errors.ErrTooManyRequests429application/json
errors.ErrInternalServerError500application/json
errors.SDKError4xx-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();

Server Selection

Select Server by Index

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:

#ServerVariables
0https://api.unkey.devNone

Override Server URL Per-Client

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:

Custom HTTP Client

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});

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

NameTypeScheme
bearerAuthhttpHTTP 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();

Development

Maturity

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.

Contributions

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

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp