Http API - Mock Redirect is a light weight developer tool, I recently developed.
Purpose of the Tool:
- When we may want to route urls to different hosts (say Dev, Test, Stage env). For ex a url of app may be routed to a host, another url of same app can be routed to different host. It can be configured at http method as well
- When we may want to mock the response rather than calling the actual service/host
- This tools also provides view of all request/response processed
How does it work:
The tools starts a http server on configured local port, and will listen to any incoming request. Based on the url mapping configuration (will see later in the section) it will decide whether the request has to routed to the external endpoint or mock response to be sent.
How to make it work:
Installation:
1. Java/Jre 8 or above is installed
2. Download the api-mock-redirect-1.0.0.jar from github , and save it in a local folder. It is executable jar - double click to open the tool.
2. Email support@lite-bean.com
Url Mapping - Configuration
1. Provide a config name (config can be later loaded, so give some meaningful name)
2. Provide the local port, where tool should listen to any incoming http request. (port > 5000 - is preferred. As initial set of ports are reserved for other purpose)
3. Configure the url for which tool needs to redirect or mock. The url should start from context, and should be valid regex string. For ex:
a. users/.* - will handle all request starting with users/
b. user/[0-9]* - will handle all request for users/<userid>
4. Configure http method, default is * - to support all methods, you may also select any method
5. Configure the option - i.e., Redirect/Mock (by default it is redirect).
6. Click edit/pencil icon, which will display fields to configure redirect/mock details.
In the below example, i have configured an url for "api/v1/employee/<empl_id_numeric>"
Redirect - Configuration
1. Select Protool - Both http & https are supported
2. Enter the host name
3. Enter the port - at which the host is serving the request. (for https it may be 443, for http it may be 80 or 8080)
In the below example, I have configured the redirect to "https://dummy.restapiexample.com/"
Url Mapping 2 - Configuration
On click of "+" will create another row in url mapping, where next url can be configured.
Here I have configured my next url for "api/v1/employees"
Lets add another url to demonstrate mock feature, select Mock option
Mock- Configuration
1. Configure Response
2. Type in response headers (click + to add more headers)
3. Enter response body
Save & Monitor Urls
Demo URL1 - Redirect
Demo URL 2 - Redirect - power of regex
Demo URL 3 - Mock
Logs:
Other Features:
Notes:
1. This is not limited to REST. SOAP over http can also be handled
2. This tool is not limited to GET. All http options are supported and can be configured
3. Some understanding of REGEX is required to configure url
4. Url Mapping and request headers requires the cell is keyed in out
5. Any click on edit, remove, add will automatically save the current state of config
6. If no matching url configured, tool will return "404 - resource not found"
7. For redirect - Few request headers (Content-length, Accept-encoding & Host) are excluded. This can be overriden by adding a file "lb/repo/ignoreRedirectHeaders". Ensure all headers needs to be excluded need to be added here.
Hope this tool will be useful one. Do let me know your feedback/comments.