Mock using the onetab API

Utilize the Onetab API to create mock servers that replicate an API’s functionality by supplying predetermined data. This simplifies the process of developing or testing your API without needing access to live data. Mock servers within Onetab rely on predefined examples stored in a collection to generate mock data. Follow the steps below to grasp how mock servers and examples work together and seamlessly integrate them into your API workflow.

Contents

Creating a mock server

Setting up a mock server in OneTab involves several steps. First, you’ll establish the foundational elements necessary for mock servers to operate. Once your mock server is active, you’ll proceed to send requests and observe how your examples dictate the returned data.

Send a request

To begin Create an HTTP GET request that interacts with a designated service, such as the OneTab Echo service. This service facilitates testing for REST or SOAP clients and allows for sample API calls.

To create and dispatch a request:

  • Open a new tab by clicking on the + icon.
  • Choose GET as the method, and input the desired URL, such as https://onetab.ai/get?test=123.
  • Click on Send to execute the request

Save the request to a collection

Generate a fresh collection and save the request within it. Collections are groups of requests that you can use to organize your work and create API workflows.

To save the request in a new collection, follow the following steps:

  1. click on Save button to save the request.

  2. Give your request a new name and description (optional).
  3. After clicking on save button then click on create collection to create a new collection.
  4. Enter name for the collection name .
  5. Select Save to save the request to the new collection.

Save a response as an example

Save a response as an example by storing the received data from the OneTab Echo service.

Click on the Save Response. The example will be saved below the request within the collection.

To rename the example, select the example name and rename the example. The request method, URL, and status code are all saved as part of the example.

Send a request to the mock server

Access the mock server by navigating to Mock Server tab.

Choose the designated mock server, then click on the copy icon to duplicate the mock server URL.

 

Initiate a new request by simply open a new tab.

Paste the copied mock URL into the request URL field, then proceed to send the request.

Upon sending the request, you might encounter an error if the mock server URL lacks a corresponding path. 

Ensure that the path appended to the mock server URL matches the path in the example’s request URL (/get), and that the selected method aligns. 

The responses generated by the mock service are contingent upon the URL and method specified in your saved examples.