Mock Http(s) Server with Apigee

Eranda Rajapakshe
4 min readFeb 8, 2019

--

Apigee is one of the famous API management tool out there. This post is only to describe how to create a mock backend using your free trial account in Apigee. (You can create a free account in Apigee in few seconds)

Mock backends are useful in most of the development tasks. Having a web-hosted, code free, configurable web backend which can be created within a few minutes is really useful for the developers. In this example, I will only create a backend that can reply back a JSON response with HTTP 200. But you can use all the Apigee features to customize your backend to demonstrate act according to scenarios. (eg: slow backend, XML responses, error response codes etc)

  1. Login to your Apigee account (if you don’t have one already you can create one here for free within few seconds [1])
  2. Go into the “API Proxies” in the home page.

3. Click on “+ Proxy” icon on the top-right corner of your screen

4. Select “No Target”

5. Give a name to the proxy and give a context path for the API and follow the succeeding steps

Finally, click on the “mockBackend” link given similar to above.

Now you have created your proxy. Following steps are to create a JSON message and to embed it into the response.

6. Now go to the “DEVELOP” tab in your proxy view

7. Click the [+] sign in the Policies bar in Navigator tool

8. From the next window, select the “Assign Message” policy and give a name (eg: mock-response) to the policy implementation

9. Copy the following content into the “mock-response” code window. You can change the policy configuration according to your preference if needs. It has a sample HTTP message header with HTTP code and a JSON body.

Click save finally.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="mock-response">
<Description>sample reponse</Description>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<Set>
<Headers>
<Header name="sample-header">from-apigee</Header>
</Headers>
<Payload contentType="application/json">{
"mock" : {
"message" : "hello from apigee"
}
}
</Payload>
<StatusCode>200</StatusCode>
</Set>
</AssignMessage>

10. Now drag-n-drop the “mock-response” icon to the response flow of the API. And click save.

11. Now your mock backend API is ready and its running in the Apigee cloud. Goto the “OVERVIEW” tab to extract the URL and execute a GET request to see the API in action.

Play around with different Apigee Policies and custom Javascripts, you will be able to include more features into your backend API.

Thanks :)

[1]. https://apigee.com

--

--