Skip to content

Latest commit

 

History

History
88 lines (61 loc) · 1.64 KB

File metadata and controls

88 lines (61 loc) · 1.64 KB

Dynamic Responses


🖥️ Try it yourself

$ spoof scaffold -o example-echo

Important

More token replacements are coming, so this document is a work in progress.
Keep an eye on this page for more enhancements.


Token Replacement

You can include sections of the request in your response, by using {{tokens}} that are replaced in each response.

Here are some examples:


{{request.body}}

The following response will contain the entire body of the request.

"response": {
  "statusCode": 200,
  "body": {
    "originalRequest": "{{request.body}}"
  }
}

If the request body is a plain text string, it will be returned in quotes, like this:

$ curl -s http://localhost:5050/api/echo --request POST --data "Hi!"

# Response
{
  "originalRequest": "Hi!"
}

If the original request body JSON, the JSON will be inserted in the correct place and re-formatted:

$ curl -s http://localhost:5050/api/echo --request POST --data "{ 'hello': 'world' }"

# Response
{
  "originalRequest": {
    "hello": "world"
  }
}

The response can also be a string, in which case the request body will be inserted in the correct place.

If the request body is JSON, it will be 'stringified'.

"response": {
  "statusCode": 200,
  "body": "You sent us: {{request.body}}"
}
$ curl -s http://localhost:5050/api/echo --request POST --data "{ 'hello': 'world' }"
"You sent us: { 'hello': 'world' }"

$ curl -s http://localhost:5050/api/echo --request POST --data "{ 'hello': 'world' }"
"You sent us: Hi!"


➡️ Next: Scaffolding