{"id":15091546,"url":"https://github.com/fern-api/typescript-sdk","last_synced_at":"2025-04-12T06:52:29.163Z","repository":{"id":197729604,"uuid":"699209630","full_name":"fern-api/typescript-sdk","owner":"fern-api","description":"Official TypeScript SDK for Fern's Public API ","archived":false,"fork":false,"pushed_at":"2024-10-17T18:42:09.000Z","size":544,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-12T06:52:19.379Z","etag":null,"topics":["built-with-fern","generated-from-ferndef","python-client"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fern-api.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-02T07:01:13.000Z","updated_at":"2024-10-17T18:41:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"7155084a-c38a-4db1-b1a6-e88c25ffb271","html_url":"https://github.com/fern-api/typescript-sdk","commit_stats":{"total_commits":55,"total_committers":5,"mean_commits":11.0,"dds":0.6181818181818182,"last_synced_commit":"469b02d1cbf512cc44957e7e5ac2b7f577ba1f28"},"previous_names":["fern-api/node-sdk","fern-api/fern-typescript"],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fern-api%2Ftypescript-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fern-api%2Ftypescript-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fern-api%2Ftypescript-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fern-api%2Ftypescript-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fern-api","download_url":"https://codeload.github.com/fern-api/typescript-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248530604,"owners_count":21119595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["built-with-fern","generated-from-ferndef","python-client"],"created_at":"2024-09-25T10:41:43.954Z","updated_at":"2025-04-12T06:52:29.132Z","avatar_url":"https://github.com/fern-api.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fern Typescript Library\n\n[![npm shield](https://img.shields.io/npm/v/@fern-api/sdk)](https://www.npmjs.com/package/@fern-api/sdk)\n[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)\n\n\u003c!-- ![](assets/logo.svg) --\u003e\n\nThe Fern Typescript library provides access to the Fern's Public API from JavaScript/TypeScript, and from the JavaScript runtime of your choice ([Node, Browser, Deno, Bun and more](#runtime-compatiblity)).\n\n## Documentation\n\nAPI reference documentation is available [here](https://buildwithfern.com/learn/api/api-reference/docs/generate).\n\nThis SDK primarily serves as a way to access Fern's **dynamic snippets** API. Fern's dynamic snippets API is meant to allow users to create code snippets for their Fern-generate SDKs with dynamic payloads.\n\nCommon use cases include:\n\n1. In-app code examples\n2. User-specific code examples in your documentation\n3. So much more!\n\n\u003cbr/\u003e\n\nNotable features:\n\n1. [Client-side execution](#client-side-execution), ideal for code examples that change often, potentially due to user input in a browser.\n2. [Dynamic code examples](#dynamic-code-examples)\n3. [Displaying default and auto-generated examples](#default-or-static-code-examples)\n\n## Installation\n\n```\nnpm install --save @fern-api/sdk\n\n# or\n\nyarn add @fern-api/sdk\n```\n\n## Usage\n\n### Client-side Execution\n\n```typescript\nimport { FernClient } from \"@fern-api/sdk\";\n\nconst fern = new FernClient({\n    token: \"YOUR_API_KEY\",\n});\n\n// Get the snippet template from the Fern API\nconst template = await fern.templates.get({\n  endpoint: {\n    method: \"POST\",\n    path: \"/api/users/search/{someFilter}\",\n  },\n});\n\n// Build a snippet with a payload, this happens on the client side,\n// without need for another API call, improving latency dramatically.\nconst snippet1 = await template.resolve({\n    pathParameters: [{\n      name: \"someFilter\",\n      value: \"test1\"\n    }]\n    requestBody: {\n      name: \"Joey\",\n    }\n  })\n\n// You can build as many snippets as you'd like!\nconst snippet2 = await template.resolve({\n  pathParameters: [{\n    name: \"someFilter\",\n    value: \"anotherTest\"\n  }]\n  requestBody: {\n    name: \"Samantha\",\n  }\n})\n```\n\n### Dynamic Code Examples\n\n```typescript\nimport { FernClient } from \"@fern-api/sdk\";\n\nconst fern = new FernClient({\n    token: \"YOUR_API_KEY\",\n});\n\nconst snippets = await fern.snippets.get({\n  endpoint: {\n    method: \"POST\",\n    path: \"/api/users/search/{someFilter}\",\n  },\n  // The payload parameter allows you to pass in the same data you would to the API,\n  // the only distinction is that the payload is structure to distinguish path and query parameters,\n  // headers and request bodies.\n  payload: {\n    pathParameters: [{\n      name: \"someFilter\",\n      value: \"test1\"\n    }]\n    requestBody: {\n      name: \"Joey\",\n    }\n  }\n});\n```\n\n### Default or Static Code Examples\n\n```typescript\nimport { FernClient } from \"@fern-api/sdk\";\n\nconst fern = new FernClient({\n    token: \"YOUR_API_KEY\",\n});\n\n// Without any payload specified, the SDK returns a snippet with the examples provided within your API spec\n// If there are no examples in your spec, a basic example is autogenerated for you.\nconst snippets = await fern.snippets.get({\n    endpoint: {\n        method: \"GET\",\n        path: \"/api/users\",\n    },\n    // The name of your organization, found in your `fern.config.json`\n    orgId: \"my_organization\",\n    // The name of the API you'd like to generate snippets for,\n    apiId: \"api\",\n    sdks: [{ type: \"python\", package: \"my_package\", version: \"0.0.3\" }],\n});\n```\n\n### Handling Errors\n\nWhen the API returns a non-success status code (4xx or 5xx response),\na subclass of [FernError](./src/errors/FernError.ts)\nwill be thrown:\n\n```ts\nimport { FernError } from \"@fern-api/sdk\";\n\ntry {\n  await fern.snippets.get(...);\n} catch (err) {\n  if (err instanceof FernError) {\n    console.log(err.statusCode);\n    console.log(err.message);\n    console.log(err.body);\n  }\n}\n```\n\n### Request Options\n\nThe HTTP Client accepts a `RequestOptions` class where you can specify\na customized timeout.\n\n```typescript\nconst snippets = await fern.snippets.get(\n    {\n        endpoint: {\n            method: \"GET\",\n            path: \"/api/users\",\n        },\n    },\n    {\n        timeoutInSeconds: 60, // increase timeout in second\n    }\n);\n```\n\n### Runtime compatiblity\n\nThe SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK\nworks in the following runtimes:\n\nThe following runtimes are supported:\n\n-   Node.js 15+\n-   Vercel\n-   Cloudflare Workers\n-   Deno v1.25+\n-   Bun 1.0+\n\n## Beta status\n\nThis SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we\nrecommend pinning the package version to a specific version in your package.json file. This way, you can install the\nsame version each time without breaking changes unless you are intentionally looking for the latest version.\n\n## Contributing\n\nWhile we value open-source contributions to this SDK, this library is generated programmatically.\nAdditions made directly to this library would have to be moved over to our generation code, otherwise\nthey would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept,\nbut know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!\n\nOn the other hand, contributions to the README are always very welcome!\n\n\u003cbr/\u003e\n\u003cimg src=\"assets/footer.svg\" alt=\"drawing\" width=\"100%\" class=\"img-fluid\"/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffern-api%2Ftypescript-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffern-api%2Ftypescript-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffern-api%2Ftypescript-sdk/lists"}