Simulate your API using saved response examples within OneTab:
Mock servers in OneTab mimic an API's behavior by providing predefined data, facilitating development or testing of your API without accessing production data. These mock servers rely on examples stored within a collection to generate mock data.
Follow the steps outlined below to understand how mock servers and examples collaborate and how you can seamlessly incorporate them into your API workflow.]
Editing the Mock Server Configuration:
- You can change the configuration for a mock server at any time. Select Mock Servers in the sidebar, then, click on the additional actions icon (...) located next to the name of the mock server and choose the option to Edit.
- You can change the mock server's name, URL, method, response code, and response. When you are done changing the configuration settings, click on "Done”.
<aside>
💡 You can't change the mock server's collection. If you need to mock a different collection, create a new mock server.
</aside>
Accessing Mock Servers:
- Utilize the mock server's URL to initiate requests. Navigate to Mock Servers in the sidebar, choose a mock server, and click on Copy Mock URL.
- Ensure that the request intended for mocking contains at least one saved example. You can send a request and save its response as an example, or define a custom example. Explore more about adding examples to a request.
- Open a new request tab (or modify the address in an existing tab) and insert the mock URL: https://mock.onetab.ai For instance: https://mock.onetab.ai/mock-endpoint The mock URL comprises the mock server's identifier and the endpoint for the request being mocked. Click on Send to forward the request to the mock server. Upon sending a request to the mock server, it will return a response based on an example with a matching path and method.
Using HTTP Access Control for a Mock:
- Besides using OneTab for requesting mock endpoints, you can also perform these requests directly within a web browser.
- A web browser initiates a cross-origin HTTP request whenever it seeks a resource from a domain, protocol, or port that differs from its own. Cross-Origin Resource Sharing (CORS) is a standardized mechanism that delineates a secure interaction between a browser and server. In this scenario, CORS pertains to how a web browser interacts with the mock endpoints hosted on the OneTab mock server.
- CORS functionality is activated for OneTab mock servers, allowing you to integrate mocked data into your web applications using the mock endpoints. Consequently, both development and production web applications can dispatch requests to your OneTab mock endpoint and receive example responses.