HAL browser
This package provides a middleware for HAL APIs.
The middleware looks for HAL and JSON responses, and automatically converts them into a HTML interface if a browser access them.
It does so via the Accept: text/html
header. If this header is not provided,
the middleware does nothing.
It automatically decorates the following formats:
application/json
application/problem+json
application/hal+json
text/markdown
Screenshot
An example. If a API normally returns the following HAL format:
The browser will automatically convert it to this HTML format:
This screenshot is an example of the browser automatically formatting a .csv
and parsing HTTP Link
headers:
The following example converts this:
And automatically turns the templated link into a form:
Supported frameworks
Installation
npm install hal-browser
Getting started
Curveball
;; ;app.usehalBrowser;
Express
Express support is handled via a special express middleware. Check out the hal-browser-express package.
Koa
TODO
Options
The halBrowser function takes an options object, which can take the following settings:
title
- Change the main title.stylesheets
- Provide your own stylesheets. This is an array of strings. these are relative urls, and they are automatically expanded based on theassetBaseUrl
setting.navigationLinks
- Specify (or remove) links that show up in the top navigation.serveAssets
- by default the browser plugin will also take responsibility for serving icons and stylesheet. If you're hosting these assets elsewhere, set this tofalse
.defaultLinks
- A list of links that will show up by default, whether or not they were specified by the API. By default ahome
link is added here.hiddenRels
- List of relationship types that will be hidden from the user by default. This can be used for links that are simply not interesting for a human to see. (default:['self', 'curies']
.
Example:
app
Future features
- Add a link to allow the user to see the raw format.
- Show metadata, such as
Last-Modified