Skip to main content

Create and Manage Mock API Responses

With mockforme, you can create up to 10 different responses for each API endpoint. This flexibility enables you to simulate various use cases, test different scenarios, and evaluate your API's behavior effectively across a range of conditions.

Accessing the API Response Page

Follow these steps to access the API Responses page:

  1. Click on Collections in the left sidebar.
  2. On the Collections page, click the Apis button.
  3. On the Apis page, click the Responses button.
  4. You will be directed to the API Responses page, where you can create and manage your responses.

Accessing the API Response List

Once you're on the API Responses page, click the Create New button to begin creating a new response.

API Response list in mockforme

Creating a New API Response

To create an API response, you will need to provide the following information:

  • Response Body: The mock API response, which can be Text or JSON.
  • Response Code: The HTTP status code to return (e.g., 200 for a successful response).
  • Response Title: A descriptive label for the API response.
  • Response Description: A detailed explanation of the API response and its purpose.
Create new API response in mockforme

Add Response Using JSON Editor

If you're creating a JSON response, you can take advantage of the JSON Editor for easier editing. Once you've entered a valid JSON object, you will see the View in JSON Editor link. Clicking this will open the JSON editor for more advanced modifications.

JSON Editor link for API response – mockforme

Clicking the link will display the editor as shown below:

JSON editor view for API response – mockforme

Once you're happy with your response, click Save to finalize the response. You will be redirected to the API Response Listing page.

Saved API response list in mockforme

By default, the status of a newly created response is set to Off. To activate the response, simply toggle the Status to ON.

Note: Only one response can be active at a time for each API endpoint.

Generate Mock Data Using Faker.js

mockforme allows you to generate mock response data using faker.js. This is especially useful when you need dynamic and realistic data for your API responses.

To generate mock data:

  1. Click the Generate Schema button on the Create New API Response page.
  2. A popup will appear where you can customize the data type (e.g., string, number, boolean, date).
Generate Schema Button in mockforme

Once you click on Generate Schema, you'll be presented with a schema preview:

Generated schema for API response – mockforme

You can then copy the generated schema and use it directly in the API Response textarea.

Customize API Response Headers

mockforme also allows you to customize response headers for your mock APIs. This feature is available when you edit an existing API response.

  1. Click the Edit button for the response you want to modify.
  2. In the Response Header section, add the key and value for each custom header.
Customize API response headers in mockforme

After entering the custom headers, click Save to finalize your changes.

Saved custom response headers – mockforme

Benefits of Creating Custom API Responses

  • Simulate real-world scenarios with dynamic API responses based on different conditions
  • Test different status codes (e.g., 200, 404, 500) and response data to improve your application's robustness
  • Generate realistic mock data using Faker.js for more accurate testing
  • Customize response headers for advanced testing of header-based functionality