Learn how to create partial mocks of existing APIs with Mockoon's proxy mode in three easy steps
During the development of an application, you may use an API that is still under development. Rather than waiting for new API endpoints to be added and rely on your memory or documentation to continue your application development, you could use Mockoon to create a partial fake API. The idea is simple. Mockoon would serve the API endpoints you define while forwarding anything else to the URL of your choice. Let's dive through this with a simple example.
To learn more about APIs and API mocking in general, head over to our API guide or API mocking guide
The first step is to create a new API in Mockoon or use one you already have.
To learn more about how to set up your first mock API with Mockoon, head over to the Getting started tutorial.
As soon as you have your new mock API, you are ready to enable the proxy mode and forward all the calls to another URL. For this tutorial, we will be using the Star Wars API available at https://swapi.dev/api/
. Head over to the environment proxy settings by clicking on the "proxy" tab at the top of the window. Then, enable the proxy mode and add the Star Wars API URL to which Mockoon will forward the requests:
After creating your API, enabling the proxy mode, and adding the correct target URL, you need to add the missing API endpoints.
The Star Wars API does not have any character with an ID above 83, and we want to add a missing one with id number 90. As is, calling GET /people/90
would return a 404. So, we will be adding the following body to a new GET /people/90
route:
Copy{ "name": "Mock Oon", "height": "50", "mass": "10", "hair_color": "black", "skin_color": "grey", "eye_color": "grey", "birth_year": "2017", "gender": "raccoon" }
To configure this missing endpoint, click on the blue "plus" button at the top of the endpoints list. Then, set the path to /people/90
and copy-paste the JSON body above.
You are ready to use your partial mock. Start the API by clicking on the green "play" icon at the top of the window.
You can now make a call to an existing endpoint of the Star Wars API, like /planets/1
, and get the expected result from the Star Wars API, forwarded by Mockoon:
You can also call your custom endpoint GET /people/90
and see that Mockoon intercepted your call and returned the body you defined in your new route.
Finally, you can check the different calls that have been made to Mockoon by going to the environment logs. You will see that the forwarded calls have a blue "shield" icon next to them, while the requests caught by Mockoon's routes have a green "tick" icon. To open the requests logs, click on the "clock" icon in the upper right corner of the screen:
You are now ready to unleash your creativity and create more awesome partial mocks!
Learn how to create global rules to protect all your routes at once.
Read moreUse global variables to save the state between requests and simulate complex workflows and scenarios in your mock API.
Read moreLearn how to create your first mock REST API with Mockoon in less than 5 minutes
Read more