title | description |
---|---|
Generate your first SDK |
Use Fern's CLI tool to generate your first SDK. |
If you'd rather get started immediately, you can use Fern's CLI tool to generate your first SDK.
### Install the Fern CLIFirst, install the CLI tool by running the following command:
npm install -g fern-api
```bash
fern init --openapi path/to/openapi.yml
```
If your OpenAPI spec is hosted on the web, you can use the URL:
```bash
fern init --openapi https://api.example.com/openapi.yml
```
This will create a `fern` folder in your current directory with the OpenAPI spec.
```sh
fern/
鈹溾攢 fern.config.json # root-level configuration
鈹斺攢 api/ # your API
鈹溾攢 generators.yml # generators you're using
鈹斺攢 openapi/
鈹溾攢 openapi.yml # API-level configuration
```
</Accordion>
<Accordion title="Fern Definition">
If you'd like to use the Fern Definition, you can initialize the Fern folder
by running the following command:
```bash
fern init
```
This will create a `fern` folder in your current directory with the Fern Definition.
```sh
fern/
鈹溾攢 fern.config.json # root-level configuration
鈹斺攢 api/ # your API
鈹溾攢 generators.yml # generators you're using
鈹斺攢 definition/
鈹溾攢 api.yml # API-level configuration
鈹斺攢 imdb.yml # endpoints, types, and errors
```
</Accordion>
Run fern check
to ensure that your API Definition is valid. If there are any errors,
you will need to fix them before proceeding.
You can now use the SDK in your application. Here's an example of how you can use the SDK:
```sh fern add fern-typescript-node-sdk --group sdk ``` ```sh fern add fern-python-sdk --group sdk ``` ```sh fern add fern-java-sdk --group sdk ``` ```sh fern add fern-go-sdk --group sdk ``` ```sh fern add fern-ruby-sdk --group sdk ```Next up, run the following command to generate the SDK:
fern generate --group sdk
This will create a fern
folder in your current directory with the Fern
Definition. For example, if you're generating a TypeScript SDK, the folder structure
will look like this:
sdks/
typescript/
src/
鈹溾攢 index.ts
鈹溾攢 Client.ts
鈹斺攢 api
鈹斺攢 errors
鈹斺攢 serialization