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:

users/create.postino
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 \n and \r\n line 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.

  • METHOD is the first word. GET, POST, PUT, PATCH, DELETE, HEAD and OPTIONS are 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: PURGE and M3THOD are valid, get is an error.
  • URL is 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 as Name: 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.

MarkerContent
::: queryQuery parameters, key = value lines
::: auth basic, bearer, apikey or oauth2Authorization, field = value lines
::: body jsonRaw JSON text
::: body textRaw text
::: body xmlRaw XML text
::: body formURL-encoded form fields, key = value lines
::: body multipartmultipart/form-data fields, key = value lines; @path sends a file, @@text is the text @text
::: prePre-request JavaScript
::: postPost-response JavaScript
::: docsFree notes in Markdown, never sent
  • Kinds are case sensitive: ::: Query is an error.
  • Each kind appears at most once. A second ::: body, even of another type, is an error.
  • query, pre, post and docs take no argument. body requires exactly one: json, text, xml or form. auth requires exactly one too: basic, bearer, apikey or oauth2.
  • 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:

TypeFields
basicusername, password
bearertoken
apikeyname, value, in (header or query)
oauth2profile, 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 an in other than header or query is an error.
  • A missing field is empty, and in is header when missing. Postino writes the fields in the order above, leaves out the empty ones and always writes in.
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:

  1. The request line.
  2. The headers, in their order.
  3. 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.
  4. 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 lineIn the fileRead back as
::: not a section\::: not a section::: not a section
\::: had a backslash\\::: had a backslash\::: had a backslash
regular textregular textregular 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:

ErrorCause
missing request lineThe file is empty or only has blank lines.
missing URL in request lineThe first line has a method and nothing else.
invalid methodThe method has a lowercase letter.
invalid header lineA header has no colon. A # line without a colon, written as a comment in the header block, causes this too.
expected a section markerA line that is not a marker where a section should start, typically a body without its ::: body line.
unknown section kindA marker other than query, body, pre, post or docs, or the wrong case.
duplicated sectionThe 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 argumentAn 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.

environments/staging.env
# Staging
baseUrl=https://staging.example.com
greeting = Hello, world
  • One KEY=value per 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 greeting is " 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 \n and \r\n are 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.

Found a mistake? Edit this page on GitHub or open an issue.

↑↓to move ↵to open /or Ctrl Kto search from any page