Restep2½

Tools · Use an API · v0.2.0

restep-exportRequests, ready

Turns a discovery document into ready-made requests for Bruno, Postman or .http files: lists with sample filters, writes with their headers, and the actions.

Node 18 or later · npm install -g restep-export

Why use it

No copying URLs by hand

Every collection, every declared filter, sort, fields, count, create, update, delete and action, as requests you can send straight away. From the discovery document, which already says all of it.

The headers Restep asks for

Idempotency-Key on creates, If-Match on updates and deletes, application/merge-patch+json on PATCH. The requests teach the contract while you use them.

Your client, your choice

.http files for VS Code and JetBrains, a Bruno collection or a Postman one. Or all three at once.

Your token stays out

The token it uses to read the API never lands in the files. They get a {{token}} variable, kept as a secret in Bruno and in a separate file for JetBrains.

How it works

  1. It reads the discovery document: from a URL (the root, or the document linked with rel="service-desc") or from a JSON file. With a file it makes no request at all. Its restep has to follow the grammar (1.0, 1.0-draft.6, 1.0-rc.1…) with major version 1: anything else is an error, not something to export as plain core (§1.1).
  2. With a URL, it also fetches the item, create, update and action input schemas that are links on the same origin (§4.3), and the first item of each collection, to use its id as the example.
  3. For each collection and each singleton it builds the requests its declaration allows (tables below), with sample values of the declared type for filters and a sample body from the schema for writes. Filters, operators and actions with a type, on or method it does not know are left out (§4.2).
  4. It writes them in each format you ask for. With several formats, one subfolder per format.

For now its messages and the names and notes of the requests it generates are in Spanish: “Listar books”, “Obtener books”, “Crear en books”. Paths, headers and bodies are the same in any language.

Install and run

Node 18 or later, no dependencies. Run it with npx, or install it with npm install -g restep-export.

npx restep-export https://demo.restep.wubytes.com/ --to http --out requests

Without --to it writes all three formats; without --out, into ./restep-export. It exits with 0 when it has written everything and 2 when it cannot (arguments, network or an invalid document).

Examples

All three formats from the demo API

$ npx restep-export https://demo.restep.wubytes.com/ --to http,bruno,postman --out requests
http: /home/ana/requests/http
bruno: /home/ana/requests/bruno
postman: /home/ana/requests/postman
4 colecciones, 42 peticiones.

$ find requests -type f | sort
requests/bruno/books/Accion-new-coleccion.bru
requests/bruno/books/Actualizar-books.bru
requests/bruno/books/Borrar-books.bru
requests/bruno/books/Campos-de-books.bru
requests/bruno/books/Contar-books.bru
requests/bruno/books/Crear-en-books.bru
requests/bruno/books/Filtrar-books-por-category-eq.bru
  ⋮ one .bru per request, one folder per collection
requests/bruno/books/folder.bru
requests/bruno/bruno.json
requests/bruno/environments/local.bru
  ⋮
requests/http/.vscode/settings.json
requests/http/books.http
requests/http/categories.http
requests/http/http-client.env.json
requests/http/http-client.private.env.json
requests/http/products.http
requests/http/shop.http
requests/postman/Restep-demo.restep.wubytes.com.postman_collection.json

From a file, for another server

curl -s https://api.example.com/ > discovery.json
npx restep-export discovery.json --to bruno --out bruno --base-url https://staging.example.com

A discovery document does not say where it lives, so with a file base_url is http://localhost:8080 unless you give --base-url. There is no sample id either: <collection>_id is 1 until you change it.

Relationships and subcollections

Against the reference server, which announces relations, each collection with includable relationships gets an “Incluir relaciones” request, and the reviews subcollection takes as parent a book that has reviews:

$ npx restep-export http://localhost:8080/ --to http --out requests
http: /home/ana/requests
6 colecciones, 71 peticiones.

$ grep -A3 "Incluir" requests/products.http
### Incluir relaciones de products
# Relaciones incluidas: category, category.parent, category.showcase (§9). Una relación a varias colecciones lleva type en cada objeto, y una a un elemento de una subcolección, href (§3).
GET {{base_url}}/products?include=category,category.parent,category.showcase&limit=10
Accept: application/json

$ head -12 requests/reviews.http
  ⋮
@reviews_path_book_id = 12
@reviews_id = 3
  ⋮
GET {{base_url}}/books/{{reviews_path_book_id}}/reviews?limit=10

An API that needs a token

npx restep-export https://api.example.com/ --token "$TOKEN" --out requests

The token is used to read discovery and the sample ids, and is not written anywhere. If the API announces the oauth extension, every request gets Authorization: Bearer {{token}}; for an API that wants a token without announcing it, add --auth bearer.

What each format contains

http: REST Client (VS Code) and the JetBrains HTTP client

One .http file per collection, plus http-client.env.json (environment local with base_url and an empty token), http-client.private.env.json (just the token, for JetBrains; keep it out of version control) and .vscode/settings.json with the same environment for REST Client. This is the start of books.http from the demo, and its writes:

# Restep demo.restep.wubytes.com · books
# Generado por restep-export 0.2.0 a partir del descubrimiento (Restep 1.0-draft.6).
# Books in the catalogue of El Marcapáginas, one per edition.
# base_url y token salen del entorno (http-client.env.json o .vscode/settings.json).

@books_id = 12
@books_etag =

### Listar books
# Pagina siguiendo next de la respuesta hasta que sea null; el cursor es opaco (§5.2, §6.4).
GET {{base_url}}/books?limit=10
Accept: application/json


### Filtrar books por rating (ge)
# Operadores declarados para rating: ge, null (§6.1).
GET {{base_url}}/books?filter[rating][ge]=3&limit=10
Accept: application/json

  ⋮ one request per declared filter, then sort, fields and count

### Crear en books
# Repetir la petición con la misma Idempotency-Key no crea otro elemento (§7.1); cámbiala para crear otro.
POST {{base_url}}/books
Accept: application/json
Content-Type: application/json
Idempotency-Key: "6ed2d062-3d18-44bc-90c6-83226a857384"

{
  "title": "La niebla de Portugalete",
  "price": "10.00",
  "year": 1,
  "published": "2026-01-01",
  "reading_time": "PT6H",
  "rating": 1.5,
  "signed": false
}


### Actualizar books
# Merge patch (§4.3). If-Match lleva la ETag de «Obtener books», con sus comillas (§7.2).
PATCH {{base_url}}/books/{{books_id}}
Accept: application/json
Content-Type: application/merge-patch+json
If-Match: {{books_etag}}

{
  "title": "La niebla de Portugalete"
}

In .http files you copy the ETag from “Obtener books” into @books_etag by hand: REST Client and JetBrains chain responses with different syntax, and the files work in both.

bruno: a Bruno collection

bruno.json, a folder per collection with its folder.bru, one .bru per request and environments/local.bru with every variable and token as a secret. Here “Obtener books” stores the ETag after the response, so “Actualizar” and “Borrar” can use it at once; “Listar” stores next in books_next:

meta {
  name: Obtener books
  type: http
  seq: 13
}

get {
  url: {{base_url}}/books/{{books_id}}
  body: none
  auth: none
}

headers {
  Accept: application/json
}

script:post-response {
  const etag = res.getHeader('etag');
  if (etag) bru.setVar('books_etag', etag);
}

docs {
  Guarda la ETag de la respuesta en books_etag para usarla en If-Match (§7.2).
}
# environments/local.bru
vars {
  base_url: https://demo.restep.wubytes.com
  books_id: 12
  books_etag:
  products_id: 1
  products_etag:
  categories_id: 1
  categories_etag:
  shop_etag:
}

vars:secret [
  token
]

postman: a Postman v2.1 collection

One JSON file, <name>.postman_collection.json, with a folder per collection and every variable as a collection variable (base_url, token, books_id, books_etag…). Import it in Postman. The same ETag and next chaining goes in a test script:

{
  "name": "Obtener books",
  "event": [{
    "listen": "test",
    "script": {
      "type": "text/javascript",
      "exec": [
        "const etag = pm.response.headers.get('ETag');",
        "if (etag) pm.collectionVariables.set('books_etag', etag);"
      ]
    }
  }],
  "request": {
    "method": "GET",
    "header": [{ "key": "Accept", "value": "application/json" }],
    "url": {
      "raw": "{{base_url}}/books/{{books_id}}",
      "host": ["{{base_url}}"],
      "path": ["books", "{{books_id}}"]
    },
    "description": "Guarda la ETag de la respuesta en books_etag para usarla en If-Match (§7.2)."
  }
}

The requests for each collection

RequestWhen
List, with limit (the smaller of 10 and max_limit)If methods includes GET or is not declared
One per declared filter, with its first operator and a value of its type (§6.1)With query
Sort by the first two keys of sort other than id, the first descending (§6.2)With query and sort
fields with two top-level fields (§6.3)With query
count=true&limit=1 (§6.5)If count is declared
Include relations: include with those declared with "include": true and, up to include_depth, those of their targets (category,category.parent); a relationship to several collections only at the end (§9)With relations
Get one itemIf item_methods includes GET or is not declared
Create, with a sample body from the create schema and an Idempotency-Key (§7.1)POST; the key, with writes
Update with a merge patch of one field and If-Match: {{<collection>_etag}} (§7.2)PATCH; If-Match, with writes
Delete, with If-MatchDELETE; If-Match, with writes
Each action, at /collection:name or /collection/{{id}}:name, with its method and a body from its input (§11.1)With the actions extension. With writes, an Idempotency-Key when the action declares "idempotent": false

Where the collection says "id_from": "client", the create body carries a random id (a UUID, §13.6); without id_from, or with "server", "either" or a value it does not know, it carries none (§5.1). Where idempotency says "anonymous": false and the export has no credentials (no --auth bearer or oauth, no --token or -H Authorization), the requests carry no Idempotency-Key (§7.1). Every POST body, creates and actions, goes with Content-Type: application/json, and a literal + in a query value as %2B.

Singletons

Each resource in singletons (§5.9) becomes a folder (or a .http file) with “Obtener” and, when methods includes PATCH or is not declared, “Actualizar”, a merge patch with If-Match: {{<name>_etag}}. One whose path is a template or that carries parent is ignored, with a warning. If it shares its name with a collection, its folder is called <name>-recurso. On the demo, shop.http:

### Obtener shop
# Recurso suelto (§5.9). Guarda la ETag en shop_etag para usarla en If-Match (§7.2).
GET {{base_url}}/shop
Accept: application/json


### Actualizar shop
# Merge patch (§5.9). If-Match lleva la ETag de «Obtener shop» (§7.2).
PATCH {{base_url}}/shop
Accept: application/json
Content-Type: application/merge-patch+json
If-Match: {{shop_etag}}

{
  "name": "ejemplo"
}

Variables: base_url and token in the environment, <collection>_id (the sample id), <collection>_etag (with writes) and <collection>_path_<var> for each variable of a URI template in a subcollection. With a running API, those variables take the id of a parent item that has items in the subcollection, and <collection>_id one of them, so that “Obtener” does not give 404; from a file or with --no-samples, they are 1.

Sample bodies carry the required fields and the optional scalar ones that are not readOnly. Optional objects, such as relations and language maps, are left out so the example does not point at an item that does not exist. The Idempotency-Key values are fixed UUIDs made at export time, in quotes as Structured Fields wants: sending the request again does not create another item, which is exactly the point. Change the key to create another.

Options

restep-export <url|discovery.json> [options]

OptionWhat it does
--to <formats>http, bruno or postman, several separated by commas. All three by default
--out <folder>Where to write (./restep-export). With several formats, one subfolder per format
--base-url <url>The value of base_url. By default, the API root without the final /; with a file, http://localhost:8080
--name <name>The collection’s name. By default Restep <host>, or Restep with a file
--auth auto|bearer|noneAdds Authorization: Bearer {{token}}. auto, the default: only if the API announces oauth
--token <token>Token to read the API while exporting. Never written to the files
-H, --header "Name: value"An extra header to read the API. Repeatable. Not written either
--no-samplesDoes not ask the API for a sample id per collection
-h, --helpHelp

Limits

  • Of relations it only generates the read with include: the bodies do not link relationships. It does not cover sync, batch, filter-expr or query-method.
  • Without a running API (from a file or with --no-samples), the variables of a subcollection are 1.
  • Filter values are samples. They may return no items, but they return 200.
  • The body generator only understands the simple parts of JSON Schema: type, enum, const, default, examples, anyOf and oneOf, a flat allOf, a pattern tried against a few candidates, and the date, date-time, email, uri and uuid formats. It does not follow $ref. A string with another format and no examples gets "ejemplo", which the server may refuse.
  • Schemas linked from another origin are not fetched, and are treated as missing. Credentials only go to the API’s origin, and a link whose scheme is neither https nor the root’s (data:, file:) is not followed.
  • No requests for named filters (named_filters, §6.1), nor for fields on a singleton.
  • Deprecation notices (deprecations, §5.5) are not marked on the requests that use what they retire.
  • “Obtener” stores the ETag header; it does not read _etag from the body, which §7.2 guarantees even if a proxy weakens the header.
  • Relationships with href (to an item of a subcollection or from a singleton) are not used: the sample bodies carry no relationships.
  • It uses no experimental part (sync, batch, filter-expr, query-method, inherit), so it does not depend on the declared draft.

Explorer

Browse any Restep API from this site: query forms built from discovery, writes, actions, errors explained and the curl for every request.

· Open the explorer

restep (CLI)

A command line client that learns the API from discovery: get, create, update, delete, actions, every page, CSV, and completion in zsh and bash.

· restep-cli on npm

restep-sync

An offline-first client: a local replica kept up to date incrementally, writes that queue while offline, and conflicts resolved your way.

· restep-sync on npm

All the tools