Fern Definition isn’t recommended for new customers and Fern isn’t accepting feature requests for this format. It remains supported for existing users.
In Fern, you organize related endpoints into a Service. This grouping improves clarity and makes the generated SDKs more idiomatic.
Each service defines:
To define a service with an empty base path use the empty string: base-path: ""
By default, section names in your API Reference come from service file names (e.g., user.yml becomes “User”). To override the display name of a section, use the section property in your docs.yml.
SDK method names are derived directly from the service file name and endpoint key. The file name becomes the namespace and the endpoint key becomes the method name.
For example, given the following definition:
Fern generates a method called client.users.create().
An endpoint includes:
Each endpoint has a URL path.
The full path for the endpoint is the concatenation of:
base-pathpathThe display name will appear as the title of an endpoint. By default, the display name is equal to the ‘Title Case’ of the endpoint name. If you would like to customize the endpoint name, you can set the display name.
In the example below, “Add a new plant to the store” displays as the title of the endpoint page within the API Reference.
Supply path parameters for your endpoints to create dynamic URLs.
Services can also have path-parameters:
Each endpoint can specify query parameters:
allow-multipleUse allow-multiple to specify that a query parameter is allowed
multiple times in the URL, as in ?filter=jane&filter=smith. This will alter
the generated SDKs so that consumers can provide multiple values for the query
parameter.
Each endpoint can override the auth behavior specified in the service.
Each endpoint can specify request headers:
Services can also specify request headers. These headers will cascade to the service’s endpoints.
Endpoints can specify a request body type.
If the request body is an object, you can inline the type declaration. This makes the generated SDKs a bit more idiomatic.
Endpoints can specify a response, which is the type of the body that will be
returned on a successful (200) call.
You can also use the status-code field to specify a custom status code
for a success response.
Fern supports offset, cursor, URI, and path-based pagination schemes. To set up auto-pagination in generated SDKs:
pagination fieldoffset, cursor, next_uri, or next_path)results are located using dot-access notation.Include step in most offset pagination configurations to ensure the offset increments by the page size. Use has-next-page when your API returns a boolean indicator for additional pages.
The pagination field supports the following properties:
Mark an endpoint as idempotent to allow SDK users to specify idempotency headers for safe request retries. You must also configure idempotency headers in your api.yml to define which headers are available.
Endpoints can specify error responses, which detail the non-200 responses that the endpoint might return.
You can learn more about how to define errors on the Errors page.
When you declare an example, you can also specify some examples of how that endpoint might be used. These are used by the compiler to enhance the generated outputs. Examples will show up as comments in your SDKs, API documentation, and Postman collection.
You may add examples for endpoints, types, and errors.
If you’re adding an example to an endpoint and the type already has an example, you can reference it using $.
Examples contain all the information about the endpoint call, including the request body, path parameters, query parameters, headers, and response body.
You can also specify examples of failed endpoints calls. Add the error
property to a response example to designate which failure you’re demonstrating.
If the error has a body, then you must include the body in the example.
To avoid duplication, you can reference examples from types using $.