Restep2½

Tools · Use an API · v0.2.0

ExplorerBrowse any API

Collections, query forms built from discovery, items with their relations, writes, actions and errors explained, with the curl for every request. In your browser, nothing to install.

In the browser · nothing to install

Why use it

Swagger UI without OpenAPI

Type the root of a Restep API and the whole interface comes out of its discovery document: collections, query forms, items, writes and actions. Nothing to describe twice.

Forms that know the types

Each filter offers only its declared operators, with the right control: a list for an enum, yes or no for null, a date picker for a date. Sort keys, fields and limit up to max_limit, too.

Every request as curl

The last eight requests stay below, each with its curl, the response headers and the body. Errors come explained: what the code means and what to do about it.

Nothing to install

It runs in this site, in English and Spanish, with no dependencies, no CDN and no outside fonts. Your token stays in the tab and only goes to the API.

How it works

  1. You type the API’s root and press Explore. The page requests it straight from your browser, with fetch: there is no server of ours in between.
  2. If the root is the discovery document (a JSON object with a restep string), it uses it. If not, it follows the first Link with rel="service-desc" that leads to one. If there is none, it assumes only core and lets you go to any path by hand.
  3. From discovery it draws the overview and, for each collection, the query form, the item view and the write forms.
  4. Where you are lives in the page’s address, as #api=<root>&path=<path and query>. Back and forward work, and you can share a link to a filtered page or an item. The token never goes in it.

Open an API

The demo

The quickest way to see it: the demo API, a bookshop with books, products named in several languages and nested categories. It allows CORS, and you can write to it: the data goes back to the start every hour.

Your API

Open the explorer, type the root of your API (for example https://api.example.com/v1/) and press Explore. If it needs a token, open Token and language, paste it and press Use.

The explorer runs on restep.wubytes.com and your API is somewhere else, so the browser only lets them talk if your API allows CORS. That is the one thing you may need to change: see the next section.

An API on your machine

An API on http://localhost:… works from this site in Chrome and Firefox, which treat localhost as secure, as long as it sends the CORS headers. Chrome may also ask for Access-Control-Allow-Private-Network: true on the preflight. Any other API on plain http: is blocked by the browser as mixed content: it needs https:.

If you build on restep-server, the cors: true option answers the preflight and exposes the headers. The single-file reference server sends no CORS headers, so with it you have to serve the explorer and the API from the same origin.

What your API has to send (CORS)

# On every response, errors included:
Access-Control-Allow-Origin: *              # or https://restep.wubytes.com
Access-Control-Expose-Headers: ETag, Location, Link, Allow, WWW-Authenticate, Retry-After,
  Idempotent-Replayed, Preference-Applied, Content-Language, Deprecation, Sunset, Accept-Patch

# On the preflight (OPTIONS with Access-Control-Request-Method):
Access-Control-Allow-Methods: GET, HEAD, POST, PATCH, DELETE
Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-None-Match,
  Idempotency-Key, Prefer, Accept-Language
Access-Control-Max-Age: 600

Without a header in Expose-Headers, the browser hides it from the page even though it arrived. What you lose with each one:

  • ETag: the explorer cannot read an item’s ETag, so to write with If-Match it needs _etag in the representation. It tells you when there is neither.
  • Location: after a create it goes to the new item by the id in the body instead.
  • WWW-Authenticate: it cannot show the challenge of a 401 or the link to the OAuth metadata. The oauth extension already asks you to expose it.
  • Link: it cannot follow a service-desc when the root is not the discovery document.
  • Idempotent-Replayed: it cannot tell you that a create was a replay.

Access-Control-Allow-Headers: * does not cover Authorization: name it. And Access-Control-Allow-Origin: * works with a token, because the explorer sends it in Authorization, not in cookies.

Examples

Each link opens the explorer at that spot on the demo API.

A filtered, sorted page

Crime novels, dearest first. The form above the table already has the filter and the sort key in place. Change them, and the line under the form shows the request you are about to make before you press Query:

GET /books?filter[category]=novela-negra&sort=-price

An item with translations and a relation

Product 1 has its name in five languages. The item view lists them all and marks the one tables show, chosen by your Accept-Language or your browser’s language. Its category is a link to categories/3. Under the fields you get the item’s ETag, then Edit (PATCH) and Delete (DELETE).

An error, explained

A price that is not a decimal gets a 400. The explorer shows its code, detail and parameter, and what to do: “The resource accepts it, but the value is wrong: fix it and try again.” In Requests, the same call as curl:

curl -i -g 'https://demo.restep.wubytes.com/books?filter[price]=abc' -H 'Accept: application/json'
{
  "type": "https://w3id.org/restep/1/errors#invalid_parameter",
  "title": "Bad request",
  "status": 400,
  "code": "invalid_parameter",
  "detail": "abc is not a valid decimal.",
  "parameter": "filter[price]"
}

What each view does

API overview

Restep and API versions (with a warning when it is a draft or a candidate, and nothing more on offer when it is not Restep 1), profiles, extensions, how long an Idempotency-Key is kept, announced retirements with their date (§5.5), and a Check button for the status resource. Then a card per collection with its path, description, methods, filters with type and operators, sort keys, limit, count, relations, language maps, inherited fields, actions and schemas, and a card per singleton. At the end, the full discovery document. The sidebar lists the collections and the singletons; subcollections show up there but open from an item of their parent.

Collection

  • Filters, combined with AND: Add filter, pick the field and the operator, and type or pick the value. The control follows the type: a list for enum and boolean, yes or no for null, a date picker for date, and a hint for decimal, datetime, duration and lists in in.
  • Sort, with one or more keys, each ascending or descending.
  • Fields (fields): from the item schema when it is embedded, and from the items on the page. None checked means all.
  • Include relations (include), when the API has relations: it offers the paths up to include_depth, such as category.parent, and a relationship to several collections only at the end of the path.
  • limit up to max_limit, and Count the total when count is declared, exact or estimated.

Below, the items in a table (the id opens each one), how many are on the page and the total if you asked for it. Next page follows next exactly as it came (§5.2), and First page drops the cursor. If the collection declares actions or accepts POST, their forms come last.

Item

All its fields. Language maps show every translation. Inherited fields (§11.6) say which own field they are written in and where the value comes from, from _inherited; an unknown from shows as a source you cannot see ("hidden"). Relations are links, by their href when they carry one (it is required towards an item of a subcollection), and so are subcollections. Then the item’s actions, editing and deleting.

Singleton

Each resource in singletons (§5.9), such as /shop on the demo, has its link in the sidebar and its view, with its fields and its ETag, and Edit (the minimal merge patch, with If-Match) when methods includes PATCH or is not declared. Singletons with a template in path or with parent are ignored.

Any path

The bar above the view, Path, relative to the root, goes to any path with any query, also on an API without a discovery document. What it does not recognise as a collection or an item it shows as raw JSON. Reload reads discovery again.

Requests

The last eight requests of the tab: method, path, status and time, the curl with a Copy button, the response headers that CORS lets the page read, and the body as it came.

Writes, safely

  • Create an item (POST) starts from a body with the required fields of the create schema, each with its default, its first enum value or an empty value of its type. Where the collection says "id_from": "client", the body starts with a random id; with an id_from it does not know, the id is always removed before sending (§5.1). Once created, it takes you to the new item.
  • Edit (PATCH) gives you the item as editable JSON, without id, the _ members, readOnly fields and effective inherited fields. Edit it and press Save changes: it sends only what changed, as a JSON Merge Patch (removing a field sets it to null; relations go whole). If nothing changed, it sends nothing.
  • Delete (DELETE) asks you to confirm first.

When the API announces writes:

  • If-Match goes on every edit and delete, with the item’s ETag: _etag if the representation carries it, and if not the ETag header of a full read. The form shows which one it will send. If someone changed the item meanwhile, you get a 412 and the hint to reload it and apply your change again (§7.2).
  • Idempotency-Key is generated for every POST, creates and non-idempotent actions, and shown on the form. If the request gets no response, say the network dropped, the same key stays for the retry, so the API does not repeat the effect. After any response it makes a new one (§7.1). Where idempotency says "anonymous": false, a POST without a token carries no key.

Actions (§11.1) take the ones the item lists in _actions, the ones available in its current state, or else the declared ones. Each has its method, a body from its input schema and badges for safe and idempotent. The explorer does not validate bodies against schemas before sending: the API does, and its 422 comes out with the table of errors.

What it understands of draft 6

  • Version (§1.1). restep has to follow the grammar (1.0, 1.0-draft.6, 1.0-rc.1…) with major version 1. If not, the overview says it is not Restep 1 and offers nothing else; it does not fall back to core.
  • Experimental parts (§1.2). It implements the draft 6 text of inherit, and uses it (read-only effective field when editing, origin from _inherited) only if the API announces the inherit extension and declares exactly "restep": "1.0-draft.6". With another version it ignores those members and says so in the overview. Of sync and batch it only shows what they declare.
  • Unknown values (§4.2). A filter or named filter with an unknown type is not offered, nor are unknown operators; an action with an unknown on or method (also in _actions) is not offered; a deprecation notice whose kind does not fit its place is not shown.
  • Links (§3). It requests no URL whose scheme is neither https nor the root’s.
  • Bodies and queries (§3, §5.2). Every POST, creates and actions, also with a {} body, goes with Content-Type: application/json, and a literal + in the query goes as %2B.

Your token and your privacy

  • The token is kept only in sessionStorage, so it goes when you close the tab, under a key per API origin. Forget removes it at once.
  • It is only sent to that origin: a schema or a link on another origin is fetched without it (§4.3). A shared link pointing at another API does not get your token.
  • It never goes in the link or in the curl, which uses "Authorization: Bearer $RESTEP_TOKEN".
  • Only the theme and the Accept-Language you chose go to localStorage.
  • The page loads only its own scripts and styles, under a strict Content Security Policy, and never uses innerHTML. The link to the other language keeps the API and the path, never the token.

Keyboard and screen

There are no shortcuts of its own: everything works with Tab, Enter and the browser’s back and forward. Every control has a label. On each navigation the focus moves to the view’s heading, notices are read by an aria-live region, and adding a filter or sort key moves the focus to it. The theme button cycles through automatic, light and dark, and the layout fits a phone.

Limits

  • It does not implement sync (:changes, SSE notifications), batch, filter-expr or query-method. A filter=… expression typed in the path bar is kept, but there is no form for it.
  • It does not validate bodies against the schemas before sending.
  • Subcollections only open from an item of their parent collection, found by path prefix, not by parent (§4.2).
  • Collection cards do not show id_from, collations or parent, and responses that carry Deprecation are not flagged (the header only shows in the request log).
  • A singleton has no fields form, and its relations show as JSON, without following their href.
  • It does not revalidate discovery by its Cache-Control (§4.2): it reads it again when you change API, save the token or the language, and with Reload.
  • No Prefer: return=minimal and no If-None-Match: every read goes with cache: no-store.

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