Skip to content

Using Mock Form

Sran Manpreet edited this page Sep 6, 2023 · 2 revisions

One of the pivotal pages within Mockpit is the Mock Form, which plays a central role in configuring mock endpoints.

To access the Mock Form, proceed to the Mockpit homepage and click the New Mock button:

Homepage

Upon clicking, you'll land on the Mock Form page:

Open Search Result

Mock Form Fields

Name

Assign a distinctive name to your mock. While this doesn't impact mock behavior, it aids in locating the mock on the "Manage Mocks" page.

Description

Provide a descriptive summary for the mock's purpose. Though it doesn't influence mock behavior, including details here assists both you and your colleagues in comprehending the mock's intent.

Inactive

It allows users to temporarily disable a mock API without deleting it, ensuring precise control over mock availability for testing and development.

Method

Specify the HTTP method for which the mock's endpoint will respond.

Route

Define the endpoint of the mock by providing a relative path, such as /books.

Route Preview

As you input the relative path, the Route Preview displays the complete endpoint path, incorporating the backend URL prefix.

Status Code

Set the desired response status code, such as 200 for OK or 400 for Bad Request.

Response Body type

Choose from two options:

  • Static: The content entered in the Response Body Content field will be the response body as-is.
  • Javascript: The content in the Response Body Content field will be treated as JavaScript code and the script's result will be the response's body.

Content type

Defines the content type header of the response, a.k.a. the media type of the resource.

Response Body content

This field contains the response's content. Depending on the response body type chosen, the content will either be served statically or dynamically evaluated.

Example values based on the Response Body Type

Static

[{"name": "Design Patterns in Java"},{"name": "Data Structures and Algorithms by Cormen"}]

Learn more about creating a simple static mock.

Javascript

return JSON.stringify({ date : new Date()});

Explore creating a dynamic mock with javascript.

Response Headers

Click on plus (+) icon to add a new response header. Blank Headers

Name

Specify the name of the header.

Value

Input the value of the header.

Filled Headers

This comprehensive guide simplifies the process of setting up mock configurations using Mockpit's Mock Form.

Next: Manage mocks