-
Notifications
You must be signed in to change notification settings - Fork 16
YAML request response file format
Each YAML file stored in the inout directory contains configuration for the request and the response.
The request can have any of these matchers.
request:
method: GET
url: .*sample/matching.*
response:
status: 200
The above catches all the GET request that has sample/matching
in its URL
Matching multiple headers
request:
headers:
Authorization: Bearer.*123
response:
status: 200
Matching multiple headers, partial matching
request:
headers:
Auth.*: B.*123
response:
status: 200
The same can be achieved using
request:
headers: "Auth.*123"
response:
status: 200
Matching multiple headers with partial values
request:
headers:
- "H.*1.*V.*1"
- "H.*2.*V.*2"
response:
status: 200
The above will parse a request that has the following headers
Header1: Value1
Header2: Value2
Matching a body that contains "SomeString" can be done as following
request:
body: .*SomeString.*
response:
status: 200
The YAML file can specify what status, header and body to return.
status can be defined using status
field, to return 200 use the following
request:
url: .*sample/matching.*
response:
status: 200
Headers are returned by adding the headers
field in the response object
request:
url: .*sample/matching.*
response:
headers:
Content-type: application/json
The above returns the Content-type
header
The body can be a string, a file, or an image. To return a string use the following:
request:
url: .*sample/matching.*
response:
body: some string to return
Returning json can be done as
request:
url: .*sample/matching.*
response:
status: 200
body: {"key": "or even json!"}
headers:
Content-type: application/json
Notice that we also set the content type to be json
Images files are served from the specified res
folder. To return an image file, we first need to add it in res
folder, then we can use the following YAML.
request:
url: .*sample/matching.*
response:
status: 200
body_image: cat.png
Don't forget to include cat.png
in the res folder.
Files return in the response must exist in the res
folder, in order to return a JSON file we might use the following
request:
url: .*sample/matching.*
response:
status: 200
body_file: test1.json
headers:
Content-type: application/json
res/test1.json
must exist in order for this to work.
Please note that we need to specify the Content-type
to be json too.