File format
The exact rules of .postino request files and .env environment files. Use this page to write requests by hand, generate them with a script or build another tool that reads them.
A .postino file is inspired by the .http files of some editors, but it is a separate format and is not compatible with them.
Example
A file that uses every part of the format:
POST {{baseUrl}}/users
Content-Type: application/json
Authorization: Bearer {{token}}
X-Timestamp: {{ now() }}
# X-Debug: 1
::: query
page = 1
# verbose = true
::: body json
{ "name": "{{userName}}", "id": "{{requestId}}" }
::: pre
vars.set("requestId", util.uuid());
::: post
test("created", () => {
expect(res.status).toBe(201);
});
env.set("userId", res.json().id);
::: docs
Creates a user. Needs an admin token.General rules
- The encoding is UTF-8.
- Both
\nand\r\nline endings are read. Postino always writes\n. - The file extension is
.postino. The request's name is the file name without it. - A file has three parts, in this order: the request line, the header block and the sections.
Request line
The first line that is not blank: METHOD URL.
METHODis the first word.GET,POST,PUT,PATCH,DELETE,HEADandOPTIONSare the standard methods; any other word is a custom method, kept as written.- A method must not contain lowercase letters. Digits and symbols are fine:
PURGEandM3THODare valid,getis an error. URLis the rest of the line, trimmed. It may contain{{ }}markers and a query string.
Header block
Every line after the request line, up to the first blank line or the first section marker, is a header.
- A header is
Name: value, split at the first colon, both sides trimmed. A value can contain colons:Location: https://a.test:8080/b. - A line starting with
#(spaces before it allowed) is a disabled header. The#and the spaces after it are removed and the rest is read asName: value. Disabled headers are kept in the file but not sent. - A header line without a colon is an error.
- Order is preserved, including the position of disabled headers.
Because # disables a header, the header block has no comments. Put notes in the ::: docs section.
Sections
After the header block come zero or more sections. A section starts with a marker line: three colons, a space and a kind, ::: kind, optionally followed by an argument.
| Marker | Content |
|---|---|
::: query | Query parameters, key = value lines |
::: auth basic, bearer, apikey or oauth2 | Authorization, field = value lines |
::: body json | Raw JSON text |
::: body text | Raw text |
::: body xml | Raw XML text |
::: body form | URL-encoded form fields, key = value lines |
::: body multipart | multipart/form-data fields, key = value lines; @path sends a file, @@text is the text @text |
::: pre | Pre-request JavaScript |
::: post | Post-response JavaScript |
::: docs | Free notes in Markdown, never sent |
- Kinds are case sensitive:
::: Queryis an error. - Each kind appears at most once. A second
::: body, even of another type, is an error. query,pre,postanddocstake no argument.bodyrequires exactly one:json,text,xmlorform.authrequires exactly one too:basic,bearer,apikeyoroauth2.- A section's content is every line up to the next marker or the end of the file. Blank lines at the end of a section are dropped; blank lines inside it are kept.
- Blank lines between sections are ignored. Any other line where a section marker is expected is an error.
- Sections can be written in any order. Postino writes them in a fixed order (see below).
Key and value lines
The query, body form and body multipart sections use the same line format:
key = value, split at the first=, both sides trimmed. A value can contain=.- A line starting with
#is a disabled entry. - A line without
=is a key with an empty value. - Blank lines are ignored.
GET https://api.example.com/search ::: query q = rust books filter = price>=10 # debug = true verbose
Auth section
The auth section holds what the Auth tab shows, one field = value line per field:
| Type | Fields |
|---|---|
basic | username, password |
bearer | token |
apikey | name, value, in (header or query) |
oauth2 | profile, the name of a profile of .postino/project.toml, and scope, to ask for another scope than the profile's. See OAuth 2.0 |
- Each line is split at the first
=, both sides trimmed. A value can contain=, but its spaces at the start and the end are dropped. - A line starting with
#is a comment. Blank lines are ignored. - A field the type does not have, the same field twice, a line without
=or aninother thanheaderorqueryis an error. - A missing field is empty, and
inisheaderwhen missing. Postino writes the fields in the order above, leaves out the empty ones and always writesin.
GET https://api.example.com/me
::: auth basic
username = {{username}}
password = {{password}}Empty bodies
A body section is written even when it is empty, because its type matters: ::: body json with nothing below it is an empty JSON body, and a script can fill it through req.body. A request without a body has no body section at all.
Canonical serialization
When Postino saves a request, it always writes it the same way, so that two equal requests are always byte for byte equal and git diffs stay minimal:
- The request line.
- The headers, in their order.
- If there is at least one section, one blank line and then the sections in this fixed order:
query,auth,body,pre,post,docs, separated by exactly one blank line. - A single trailing newline.
Empty sections are left out, except a typed empty body or auth (::: auth bearer with no token). A request with only a method, a URL and headers has no blank line at the end:
GET https://example.com Accept: */*
Reading a canonical file and writing it back gives the same bytes, and Postino's test suite checks it.
Escaping section markers
A script, a body or the docs might contain a line that starts with ::: , which would be mistaken for a new section. Postino escapes such lines with a backslash:
- Writing: if a line, ignoring any backslashes at its start, begins with
:::, one backslash is added in front. - Reading: if a line, ignoring any backslashes at its start, begins with
:::and has at least one leading backslash, one is removed.
| Content line | In the file | Read back as |
|---|---|---|
::: not a section | \::: not a section | ::: not a section |
\::: had a backslash | \\::: had a backslash | \::: had a backslash |
regular text | regular text | regular text |
Parse errors
A file that breaks a rule is shown as name (broken) in the sidebar, and the error names the line. The messages are:
| Error | Cause |
|---|---|
missing request line | The file is empty or only has blank lines. |
missing URL in request line | The first line has a method and nothing else. |
invalid method | The method has a lowercase letter. |
invalid header line | A header has no colon. A # line without a colon, written as a comment in the header block, causes this too. |
expected a section marker | A line that is not a marker where a section should start, typically a body without its ::: body line. |
unknown section kind | A marker other than query, body, pre, post or docs, or the wrong case. |
duplicated section | The same kind twice. |
missing body type, unknown body type | ::: body alone, or with a type other than json, text, xml or form. |
section "pre" does not take an argument | An argument after query, pre, post or docs. |
Environment files
environments/<name>.env holds the shared variables of an environment, and the optional environments/<name>.local.env the private ones, which override it.
# Staging baseUrl=https://staging.example.com greeting = Hello, world
- One
KEY=valueper line, split at the first=. - The key is trimmed. The value is kept exactly as written: no trimming, no quotes, no escapes. In the example above the value of
greetingis" Hello, world", with a leading space. - A line whose first non-space character is
#is a comment. Blank lines are skipped. - Any other line without
=is an error,missing '=' in …. - Values cannot span lines.
- If a key appears twice in one file, the first one is used.
- Both
\nand\r\nare read; Postino writes\n.
Merging .local.env
The two files are merged into one list: a key present in both keeps its position from .env and takes its value from .local.env; a key only in .local.env is added at the end. An environment needs at least one of the two files.
The environments/ folder at the root of the workspace is not a collection; it is never shown in the request tree.
Variables and template functions
{{name}} markers are replaced in the URL, header names and values, query keys and values, the fields of the auth section, form keys and values, and JSON, text and XML bodies. They are not replaced in scripts or docs. Resolution order, unknown variables and template functions are described in Environments and variables and Template functions.