Request File Format
Each request is one .json file in the workspace that holds a single JSON object.
{
"method": "POST",
"url": "{{BASE_URL}}/users",
"headers": {
"Authorization": "Bearer {{API_TOKEN}}",
"Content-Type": "application/json"
},
"body": "{\"name\": \"Jane\"}"
}
Fields​
| Field | Type | Required | Notes |
|---|---|---|---|
method | string | Yes | One of GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, CONNECT, TRACE. Must be uppercase. |
url | string | Yes | The full URL, including http:// or https://. May contain {{variables}}. |
headers | object | No | Header name → value, both strings. Missing means no headers. |
body | string | No | The raw request body. Missing means no body. |
disabled_headers | object | No | Headers switched off in the editor (a # line), kept but not sent. Missing means none. Added in 0.4; older versions ignore it. |
The smallest valid file:
{ "method": "GET", "url": "https://httpbin.org/get" }
If a file can't be parsed as a request, it still appears in the sidebar, without a method, and opening it shows an error.
How Mercury writes files​
- The JSON is pretty-printed with 2-space indentation.
- Headers are sorted by name, so saving the same request always produces the same file and Git diffs stay small.
- Empty
headers,bodyanddisabled_headersare omitted. - Disabled headers (lines starting with
#in the editor) go indisabled_headers, so switching one off doesn't delete it. They're never sent. Other#lines (notes without a:) aren't saved. - Header names are unique keys. A second header with the same name replaces the first.
- Fields Mercury doesn't know are kept. Add a
"description"by hand and saving from Mercury writes it back unchanged, after Mercury's own fields. - The file ends with a newline. A file that starts with a UTF-8 byte order mark (Notepad adds one) opens normally.
- The query string is part of
url. There's no separate params field. - Auth is the
Authorizationentry inheaders. There's no separate auth field.
Body​
The body is always a string, whatever its content type. A JSON body is stored as an escaped JSON string:
{
"method": "POST",
"url": "https://api.example.com/login",
"headers": { "Content-Type": "application/x-www-form-urlencoded" },
"body": "username=john&password=secret"
}
Mercury doesn't add a Content-Type header, so include one yourself.
A multipart/form-data body is one field per line, name=value, with name=@/path/to/file for a file and name=@@text for text that starts with @. Lines starting with # are switched off. The boundary is added when the request is sent:
{
"method": "POST",
"url": "https://api.example.com/avatars",
"headers": { "Content-Type": "multipart/form-data" },
"body": "user_id=42\navatar=@/Users/ada/avatar.png"
}
Variables​
{{NAME}} (or {{ NAME }}) in url, header values or body is replaced with a value from the selected environment when you send the request. Variables that aren't defined are sent as the literal text in headers and the body; one in the URL stops the send instead. See Environments.
Editing by hand​
You can create or edit request files in any editor. Mercury watches the workspace and reloads the open request when its file changes, unless you have unsaved edits in Mercury.
Other files Mercury uses​
These live outside the workspace, in ~/.mercury/ (or $MERCURY_HOME):
| File | Contents |
|---|---|
state.json | The last workspace, the open request file, the editor contents, the environment and the theme. Restored on launch. |
recent.json | Unsaved requests you've sent (up to 50) |
history.json | Sent requests and their responses (the newest 50, up to 7 days old) |
history.lock | Empty. Keeps two Mercury windows from writing history at the same moment |