(codeSamples)
REST APIs for retrieving Code Samples
- generateCodeSamplePreview - Generate Code Sample previews from a file and configuration parameters.
- generateCodeSamplePreviewAsync - Initiate asynchronous Code Sample preview generation from a file and configuration parameters, receiving an async JobID response for polling.
- get - Retrieve usage snippets
- getCodeSamplePreviewAsync - Poll for the result of an asynchronous Code Sample preview generation.
This endpoint generates Code Sample previews from a file and configuration parameters.
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
import { openAsBlob } from "node:fs";
const speakeasy = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const result = await speakeasy.codeSamples.generateCodeSamplePreview({
language: "<value>",
schemaFile: await openAsBlob("example.file"),
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { codeSamplesGenerateCodeSamplePreview } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/codeSamplesGenerateCodeSamplePreview.js";
import { openAsBlob } from "node:fs";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const res = await codeSamplesGenerateCodeSamplePreview(speakeasy, {
language: "<value>",
schemaFile: await openAsBlob("example.file"),
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Mutation hook for triggering the API call.
useCodeSamplesGenerateCodeSamplePreviewMutation
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/codeSamplesGenerateCodeSamplePreview.js";
Parameter | Type | Required | Description |
---|---|---|---|
request |
shared.CodeSampleSchemaInput | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<shared.UsageSnippets>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorT | 4XX | application/json |
errors.ErrorT | 5XX | application/json |
This endpoint generates Code Sample previews from a file and configuration parameters, receiving an async JobID response for polling.
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
import { openAsBlob } from "node:fs";
const speakeasy = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const result = await speakeasy.codeSamples.generateCodeSamplePreviewAsync({
language: "<value>",
schemaFile: await openAsBlob("example.file"),
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { codeSamplesGenerateCodeSamplePreviewAsync } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/codeSamplesGenerateCodeSamplePreviewAsync.js";
import { openAsBlob } from "node:fs";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const res = await codeSamplesGenerateCodeSamplePreviewAsync(speakeasy, {
language: "<value>",
schemaFile: await openAsBlob("example.file"),
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Mutation hook for triggering the API call.
useCodeSamplesGenerateCodeSamplePreviewAsyncMutation
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/codeSamplesGenerateCodeSamplePreviewAsync.js";
Parameter | Type | Required | Description |
---|---|---|---|
request |
shared.CodeSampleSchemaInput | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.GenerateCodeSamplePreviewAsyncResponseBody>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorT | 4XX | application/json |
errors.ErrorT | 5XX | application/json |
Retrieve usage snippets from an OpenAPI document stored in the registry. Supports filtering by language and operation ID.
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
const speakeasy = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const result = await speakeasy.codeSamples.get({
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
operationIds: [
"getPets",
],
methodPaths: [
{
method: "get",
path: "/pets",
},
],
languages: [
"python",
"javascript",
],
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { codeSamplesGet } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/codeSamplesGet.js";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const res = await codeSamplesGet(speakeasy, {
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
operationIds: [
"getPets",
],
methodPaths: [
{
method: "get",
path: "/pets",
},
],
languages: [
"python",
"javascript",
],
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Query hooks for fetching data.
useCodeSamplesGet,
useCodeSamplesGetSuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchCodeSamplesGet,
// Utilities to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateCodeSamplesGet,
invalidateAllCodeSamplesGet,
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/codeSamplesGet.js";
Parameter | Type | Required | Description |
---|---|---|---|
request |
operations.GetCodeSamplesRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<shared.UsageSnippets>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorT | 4XX | application/json |
errors.SDKError | 5XX | */* |
Poll for the result of an asynchronous Code Sample preview generation.
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
const speakeasy = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const result = await speakeasy.codeSamples.getCodeSamplePreviewAsync({
jobID: "<id>",
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { codeSamplesGetCodeSamplePreviewAsync } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/codeSamplesGetCodeSamplePreviewAsync.js";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const res = await codeSamplesGetCodeSamplePreviewAsync(speakeasy, {
jobID: "<id>",
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Query hooks for fetching data.
useCodeSamplesGetCodeSamplePreviewAsync,
useCodeSamplesGetCodeSamplePreviewAsyncSuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchCodeSamplesGetCodeSamplePreviewAsync,
// Utilities to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateCodeSamplesGetCodeSamplePreviewAsync,
invalidateAllCodeSamplesGetCodeSamplePreviewAsync,
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/codeSamplesGetCodeSamplePreviewAsync.js";
Parameter | Type | Required | Description |
---|---|---|---|
request |
operations.GetCodeSamplePreviewAsyncRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.GetCodeSamplePreviewAsyncResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorT | 4XX | application/json |
errors.ErrorT | 5XX | application/json |