# What is a Fern Definition?

> Fern Definition is a YAML format for API specifications. Define your REST API endpoints, data models, and errors in one source of truth.

A Fern Definition is a set of YAML files that are the single source of truth for your API. You check your Fern Definition into your repo,
inside of which describes your API requests, responses, models, paths, methods, errors, and authentication scheme.

<Note>
  Want to use OpenAPI instead? No worries, we support that [as well](/learn/api-definition/introduction/what-is-an-api-definition#openapi-swagger)
</Note>

## Fern Definition structure

To initialize a Fern Definition, simply run:

```sh
npm install -g fern-api
fern init
```

This will create the following folder structure in your project:

<Files>
  <Folder name="fern" defaultOpen>
    <File name="fern.config.json" comment="Root-level configuration" />

    <File name="generators.yml" comment="Generators you're using" />

    <Folder name="definition" defaultOpen>
      <File name="api.yml" comment="API-level configuration" />

      <File name="imdb.yml" comment="Endpoints, types, and errors" />
    </Folder>
  </Folder>
</Files>

## Definition file

Each Fern Definition file may define:

* **[Custom types](/learn/api-definition/fern/types)**. Use **custom types** to build your data model.
* **[Endpoints](/learn/api-definition/fern/endpoints)**. A **service** is a set of related REST endpoints.
* **[Errors](/learn/api-definition/fern/errors)**. An **error** represents a failed (non-200) response from an endpoint.
* **[Imports](/learn/api-definition/fern/imports)**. Use **imports** to share types across files.

```yml imdb.yml maxLines=0
service:
  auth: false
  base-path: /movies
  endpoints:
    createMovie:
      docs: Add a movie to the database
      method: POST
      path: /create-movie
      request: CreateMovieRequest
      response: MovieId

    getMovie:
      method: GET
      path: /{movieId}
      path-parameters:
        movieId: MovieId
      response: Movie
      errors:
        - NotFoundError
        - UnauthorizedError

types:
  Movie:
    properties:
      title: string
      rating:
        type: double
        docs: The rating scale from one to five stars
      id:
        type: MovieId
        docs: The unique identifier for a movie

  CreateMovieRequest:
    properties:
      title: string
      rating: double

errors:
  NotFoundError:
    http:
      statusCode: 404
    type:
      properties:
        id: MovieId

  UnauthorizedError:
    http:
      statusCode: 401
```

## Why another format?

Google built gRPC. Amazon built Smithy. Facebook built GraphQL. Palantir built
Conjure. These companies rejected OpenAPI in favor of a more concise API Definition Language.

We built Fern to productize this design and make it accessible to all
software companies.

<Info>
  Despite being a different format for describing APIs, **you are never locked in to Fern.** It's easy to convert your
  [Fern Definition to OpenAPI](/learn/api-definition/fern/export-openapi).
</Info>