Skip to main content

REST hypermedia conventions

JSON:API, HAL, HAL-FORMS, JSON-LD and Hydra are conventions for REST APIs: media types and document shapes, not schema languages. An API that follows one is still described by an OpenAPI, Swagger or RAML document. When you import that document, Apiome notices which conventions it declares, tags the catalog item with them, and checks each body against its convention.

What is recognized​

A convention is recognized from the media type of a request or response body:

ConventionMedia typeWhat Apiome records
JSON:APIapplication/vnd.api+jsonResource types (the values of data.type)
HALapplication/hal+json, application/hal+xmlLink relations (_links) and embedded resources (_embedded)
HAL-FORMSapplication/prs.hal-forms+jsonLink relations and form templates (_templates)
JSON-LDapplication/ld+jsonTypes (the values of @type)
HydraJSON-LD that uses Hydra terms (hydra:member, a Hydra @context), or a Hydra profileTypes

The catalog item lists its conventions, the operations that use each, and the details above. An API that uses only application/json has no convention.

Filter the catalog by convention​

On Bring in → Catalog, choose a convention in the filter row (All conventions): JSON:API, HAL, HAL-FORMS, JSON-LD or Hydra, or No convention for items that declare none. The menu appears once an item in your catalog declares a convention, and lists only the conventions in use. Over the REST API, pass convention to GET /v1/catalog/{tenant}; it can be repeated, and GET /v1/catalog/{tenant}/facets counts each value.

Conformance checks​

The rest-conventions lint pack runs for every REST API and checks only the conventions it declares. Its findings show on the item's Lint & score tab like any other rule.

RuleChecks
rest-conventions.jsonapi-top-levelA JSON:API document has data, errors or meta.
rest-conventions.jsonapi-data-and-errorsA JSON:API document does not require both data and errors.
rest-conventions.jsonapi-resource-objectA resource object in data has type, and id in a response.
rest-conventions.jsonapi-error-documentA 4xx or 5xx JSON:API response has errors.
rest-conventions.hal-self-linkA HAL resource has a _links.self link.
rest-conventions.hal-link-objectEvery HAL link object has href.
rest-conventions.hal-forms-templateA HAL-FORMS document has a _templates.default template.
rest-conventions.jsonld-contextA JSON-LD body has @context, or its response sends a Link header.
rest-conventions.hydra-collection-memberA Hydra collection's member is an array.

All of them are warnings. A schema that declares no properties is not checked, and a property any allOf, oneOf or anyOf branch declares counts as present. See the lint rule reference for each rule's details.

JSON Type Definition​

A JSON Type Definition schema (JTD, RFC 8927) imports as a data schema, the same way a JSON Schema does: its properties become required fields and its optionalProperties optional ones. Choose JSON Type Definition in the import wizard, or upload a .jtd.json file. See Supported formats.