# Defining a mock API

For a rule-based database, you define the mock API on the database **API** tab.

By default, the **API** tab contains a commented-out example mock API definition.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2Fqn0JfAcLUDWkN8Ue9D1K%2FMockAPI.png?alt=media&#x26;token=d95e5238-7f30-4356-9fe3-24c8097a7f91" alt=""><figcaption><p>Default view of the API tab for a database</p></figcaption></figure>

## Populating the mock API definition directly <a href="#mock-api-define-direct" id="mock-api-define-direct"></a>

One option is to enter the mock API definition directly in the definition field.

For information on the API syntax, go to [mock-api-reference](https://docs.tonic.ai/fabricate/database-mock-api/mock-api-reference "mention").

After you populate the definition, to save it, click **Save**.

## Using Fabricate AI to generate the mock API definition <a href="#mock-api-define-ai" id="mock-api-define-ai"></a>

&#x20;To use the Fabricate AI to generate the mock API definition:

1. Click **Compose with AI**.
2. On the **Compose with API** panel, provide a description of the calls to include in the mock API, then click **Generate**.
3. To add the generated results to the mock API, click **Add to API**.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2Fk2jeNhN5WsCBe5eSDfXj%2FDatabase_API_AIComposer.png?alt=media&#x26;token=76e43154-0e22-4bfd-9e75-49130333c39e" alt=""><figcaption><p>Compose with API panel with calls generated by AI based on descriptions</p></figcaption></figure>

4. On the **API** tab, to save the new definition content, click **Save**.

## Tracking the change history for the mock API definition <a href="#mock-api-change-history" id="mock-api-change-history"></a>

Every time to save the mock API definition, Fabricate adds an entry to the definition history.

You can view the changes for each saved version, and revert to a previous version.

### Displaying the change history <a href="#mock-api-history-display" id="mock-api-history-display"></a>

On the **API** tab, to display the change history, click **History**.

The **History** panel lists the versions in reverse chronological order, with the current version at the top.

When you click a version, Fabricate shows the differences from the previous version, including new and removed content.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FWv77a6FRuOzZlZaYO3fl%2FMockAPI_History.png?alt=media&#x26;token=f6589b04-28a2-40fc-bda9-b422a8dfff3f" alt=""><figcaption><p>Change history for a mock API definition</p></figcaption></figure>

### Reverting to a previous version <a href="#mock-api-history-revert" id="mock-api-history-revert"></a>

To revert the mock API definition to a previous version:

1. In the version list, click the version to revert to.
2. Click **Revert to This Version**.
