Map Mock
Map Mock is the first-class feature of EchoProxy. It is designed with love🔥, very easy to learn and use. It helps to map & mock HTTP(s) request/response elegantly.
Entrance: Click left sidebar button
Map Rule
The first step is creating a new Map Rule by clicking the +Add button. There are two Map Rule Types:
Map Local: Map HTTP(s) request to a local file, where the response Header & Body will be parsed from.
Map Remote: Map HTTP(s) request to a new URL, where the response Header & Body will be fetched from.
Method:
GET/POST…: Rule matches when request method is exactly the same.
ANY: Rule matches for any request method.
Match Type
Equals: Rule matches when request URL is exactly the same.
Wildcard: Rule matches when request URL Wildcard matched.
Regex: Rule matches when request URL Regex matched.
Map Local
Map HTTP(s) request to a local file, where the response Header & Body will be parsed from. It won’t send HTTP(s) request to the original URL.
Let’s take an example to learn Map Local. Example URL https://demo.echolabx.com/. It’s default response:
Content-Type: text/plain; charset=utf-8
Content Body:Hi: EchoProxy
Create a Map Rule with following settings:
MapLocal, GET, Equals, Enabled ✅
URL:https://demo.echolabx.com/
Set the content of Response(Header+Body) as following:
Visit the URL https://demo.echolabx.com/ again with refresh. You’ll see the response has been changed by Map Mock. New response is:
Content-Type: application/json; charset=UTF-8
Content Body:
Map Remote
Map HTTP(s) request to a new URL, where the response Header & Body will be fetched from. It will send HTTP(s) requests to the new URL when set.
Let’s take an example. We want to map URL-1 to URL-2:
URL-1: https://demo.echolabx.com/json
URL-2: https://demo.echolabx.com/json-v2
Create a Map Rule with following settings:
MapRemote, GET, Equals, Enabled ✅
URL:https://demo.echolabx.com/json
Set EchoScript with the following content:
Visit the URL https://demo.echolabx.com/json again with refresh. You’ll see the response is the exactly same with URL-2.
Update the Map Rule with following settings:
MapRemote, GET, Wildcard, Enabled ✅
URL:https://demo.echolabx.com/json*
Set EchoScript with the following content:
Visit the following URLs again with refresh. HTTP responses are changed to URL json-v2.
- https://demo.echolabx.com/json
- https://demo.echolabx.com/json?page=1
- https://demo.echolabx.com/json?age=30
Match Type
1. Wildcard
Rule matches when request URL Wildcard matched.
Only supports asterisk *.
The question ? mark is treated as an ordinary charater.
Wildcard Example A:
Wildcard Example B:
Wildcard Example C:
Wildcard Example D:
2. Regex
Rule matches when request URL Regex matched. It uses Golang Regex Syntax. We recommend to use Wildcard most of the time. Regex is much more complex than Wildcard.