# Creating a mock API for a Data Agent database

## About mock APIs

Some products or features cannot interact directly with a database. Instead, they interact with an API that in turn interacts with the database. So to test a Data Agent database that you plan to use for this type of product or feature, you need an API.

To support this type of testing with a Data Agent database, you can add a mock API to the database.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FwAD537yuFQ8SHsZqPp6G%2FDiagram_MockAPI.png?alt=media&#x26;token=d73193d7-0063-4094-8cf1-ba619ccd99ce" alt=""><figcaption><p>Diagram that shows interaction with a mock API</p></figcaption></figure>

The Data Agent creates a mock API from a Swagger file that you provide. The Swagger file contains the details for the API endpoints and parameters.

You can then call those endpoints directly from within Fabricate, to verify that the results from the database meet your expectations.

## Creating the mock API <a href="#mock-api-create" id="mock-api-create"></a>

To create a mock API, attach a Swagger file that contains the details for the API, and prompt the Data Agent to create the mock API.

You can create the mock API when you create the database. For example:

`Use the attached file to create a mock API and generate the required data.`

You can also add a mock API to an existing database. For example:

`Use the attached file to add a mock API to this database.`

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FbGOlCZVrqGt0CiwYYuVt%2FDataAgent_MockAPIPrompt.png?alt=media&#x26;token=42083815-bcab-4106-9561-d177112b05c5" alt=""><figcaption><p>Example prompt and file to create a mock API for a Data Agent database</p></figcaption></figure>

## Viewing the mock API endpoint <a href="#mock-api-view" id="mock-api-view"></a>

To display the mock API details, click the **API** link at the bottom left. The link displays the number of API endpoints.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FPbSvcsPXVYEDtldWjMpe%2FDataAgent_MockAPILink.png?alt=media&#x26;token=e25c5cd0-7f3b-47c7-8298-76f842c50ba6" alt=""><figcaption><p>API link with the number of routes in the mock API</p></figcaption></figure>

The **API** page displays:

* The base URL for requests to the API. To copy the URL, click its copy icon.
* The available endpoints. To display the associated code for an endpoint, click its expand icon.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FidoMCpYxQvXRTxbA9Duo%2FDataAgent_MockAPIDetailsEndpoints.png?alt=media&#x26;token=8dcdba38-c7ab-4d1d-95a3-4655f1ef62d7" alt=""><figcaption><p>API page with the endpoints for the mock API</p></figcaption></figure>

## Testing a mock API endpoint <a href="#mock-api-test" id="mock-api-test"></a>

To test a mock API endpoint, click the run icon.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FCcLZL9ePVpBf5P7PGGYP%2FDataAgent_MockAPITestEndpointOption.png?alt=media&#x26;token=777576e8-c906-4b1b-8289-972593afd0ab" alt=""><figcaption><p>Test option for a mock API endpoint</p></figcaption></figure>

Fabricate prompts you for any parameter values or the request body details.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FSqpo8sLkyjSLYEwFR8BU%2FDataAgent_MockAPITestDetails.png?alt=media&#x26;token=d8a77890-3d8b-4577-b69b-7cf59ce872ec" alt=""><figcaption><p>Details for testing a mock API endpoint</p></figcaption></figure>

After you provide the required information, click **Send Request**. Fabricate populates the request response.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FXv6S1lgY0J7r2uJHCHG8%2FDataAgent_MockAPITestResponse.png?alt=media&#x26;token=5db00a18-1a15-47a6-aa59-5c43e03acc4a" alt=""><figcaption><p>Response from a mock API endpoint test</p></figcaption></figure>

## Viewing the request history for the mock API <a href="#mock-api-request-history" id="mock-api-request-history"></a>

To view the history of requests to the mock API, in the **API** page heading, click **Logs**.

## Updating a mock API

From the mock API details, to delete an endpoint, click its delete icon.

You can also use the chat to upload a revised Swagger file. For example:

`Use the attached file to replace the mock API for the database.`

## Deleting a mock API

To delete a mock API, use the chat. For example:

`Delete the mock API for this database.`
