v0.4.0
OAS 3.0.3
Speakeasy Code Samples API
REST APIs for retrieving SDK usage snippets from the Speakeasy Code Samples API.
Client Libraries
REST APIs for retrieving SDK usage snippets from the Speakeasy Code Samples API.
Retrieve usage snippets from an OpenAPI document stored in the registry. Supports filtering by language and operation ID.
The registry URL from which to retrieve the snippets.
The operation IDs to retrieve snippets for.
The method paths to retrieve snippets for.
The languages to retrieve snippets for.
import { SpeakeasyCodeSamples } from "@speakeasyapi/code-samples";
const speakeasyCodeSamples = new SpeakeasyCodeSamples({
apiKey: "<YOUR_API_KEY_HERE>",
registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
});
async function run() {
const result = await speakeasyCodeSamples.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();
{
"summary": "Array of usage snippets",
"value": {
"snippets": [
{
"operationId": "getPetById",
"path": "/pet/{id}",
"method": "get",
"language": "typescript",
"code": "import { Petstore } from \"petstore-sdk\";\n\nconst petstore = new Petstore({\n apiKey: \"<YOUR_API_KEY_HERE>\",\n});\n\nasync function run() {\n const result = await petstore.pet.getById({\n id: 137396,\n });\n\n // Handle the result\n console.log(result);\n}\n\nrun();"
}
]
}
}