Creating and managing mock API endpoints

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 database that you plan to use for this type of product or feature, you need an API.

To support this type of testing, you can add mock API endpoints to the project.

Diagram that shows interaction with a mock API

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

Adding and editing mock API endpoints

To create mock API endpoints, either:

  • Attach a Swagger file that contains the details for the API, and prompt the Data Agent to create the mock API endpoints. For example:

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

    • Use the attached file to add a mock API to this project.

Example prompt and file to create a mock API for a Data Agent database
  • Prompt the Data Agent to add a mock API endpoint. For example:

    • Create a Get /Users endpoint that retrieves the list of users from the Users table.

Viewing the mock API endpoints

To display the mock API endpoints for the project, in the navigation panel, click the API link. The link displays the number of API endpoints.

API link with the number of routes in the mock API

The Endpoints view of the API page displays:

  • The base URL for requests to the API. To copy the URL, click its copy icon.

  • The authentication header for requests to the API.

  • The available endpoints. To display the associated code for an endpoint, click its expand icon.

API page with the endpoints for the mock API

Testing a mock API endpoint

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

Test option for a mock API endpoint

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

Details for testing a mock API endpoint

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

Response from a mock API endpoint test

Viewing the request history for the mock API

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

Viewing the OpenAPI specification for the mock API

Fabricate also generates an OpenAPI specification for the mock API. To view the OpenAPI specification, on the API page, click OpenAPI Spec.

OpenAPI spec for a mock API

From OpenAPI Spec view:

  • To copy the spec content to the clipboard, click Copy.

  • To download the spec, click Download.

Deleting mock API endpoints

To delete a mock API endpoint, click its delete icon.

You can also use the chat to delete either individual endpoints or the entire mock API. For example:

Delete the POST /Users endpoint from the mock API.

Delete the entire mock API for this project.

Last updated

Was this helpful?