Mockoon logo between a computer and a server icons

Create a partial mock API with Mockoon's proxy mode

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.

 Step 1. Create a new fakeAPI and enable the proxy mode

The first step is to create a new API in Mockoon or use one you already have.

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:

Recording of enabling proxy mode

 Step 2. Add the missing endpoints

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.

Recording of adding a new endpoint

 Step 3. Run the API and make test calls

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:

Screenshot of the result call

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.

Screenshot of the result call

 Step 4. Check the environment logs

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:

Recording of checking the logs

You are now ready to unleash your creativity and create more awesome partial mocks!

You might also be interested in these tutorials

Create multiple route responses with dynamic rules

Learn how to create multiple responses for an API endpoint and serve them using dynamic rules

Read more

Record API requests and HTTP traffic and auto-mock endpoints

Learn how to record entering API requests and HTTP traffic and auto-mock your endpoints with Mockoon

Read more

Self-host your mock APIs with Mockoon CLI

Learn how to create mock REST APIs and self-host them in all headless and server environments with Mockoon CLI

Read more