-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from mistweaverco/feat/docs
chore(docs): add magic-variables + formatting
- Loading branch information
Showing
3 changed files
with
68 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Automatic Response Formatting | ||
|
||
If you want to automatically format the response of an HTTP request, | ||
you can use simply add an `accept` header with the desired format. | ||
|
||
For example, if you want to receive the response in JSON format, you can add the `accept: application/json` header. | ||
|
||
```http title="automatic-response-formatting.http" | ||
POST https://httpbin.org/post HTTP/1.1 | ||
content-type: application/json | ||
accept: application/json | ||
{ | ||
"uuid": "{{$uuid}}", | ||
"timestamp": "{{$timestamp}}", | ||
"date": "{{$date}}", | ||
"randomInt": "{{$randomInt}}", | ||
} | ||
``` | ||
|
||
**NOTE:** You need to have external tools to format the response. | ||
For example, `jq` for JSON, `xmllint` for XML and HTML, etc. | ||
|
||
### Supported Formats | ||
|
||
- JSON: `application/json` | ||
- XML: `application/xml` | ||
- HTML: `text/html` | ||
|
||
### Default formatters | ||
|
||
```lua title="default-formatters.lua" | ||
formatters = { | ||
json = { "jq", "." }, | ||
xml = { "xmllint", "--format", "-" }, | ||
html = { "xmllint", "--format", "--html", "-" }, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Magic Variables | ||
|
||
There is a predefined set of magic variables that you can use in your HTTP requests. | ||
|
||
They all start with a `$` sign. | ||
|
||
- `{{$uuid}}` - Generates a random UUID. | ||
- `{{$timestamp}}` - Generates a timestamp. | ||
- `{{$date}}` - Generates a date (YYYY-MM-DD). | ||
- `{{$randomInt}}` - Generates a random integer (between 0 and 9999999). | ||
|
||
To test this feature, create a file with the `.http` extension and write your HTTP requests in it. | ||
|
||
```http title="magic-variables.http" | ||
POST https://httpbin.org/post HTTP/1.1 | ||
content-type: application/json | ||
accept: application/json | ||
{ | ||
"uuid": "{{$uuid}}", | ||
"timestamp": "{{$timestamp}}", | ||
"date": "{{$date}}", | ||
"randomInt": "{{$randomInt}}", | ||
} | ||
### | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters