All Projects → curveball → browser

curveball / browser

Licence: MIT license
A HAL browser middleware for node.js

Programming Languages

typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to browser

jesi
Hypermedia API Accelerator
Stars: ✭ 19 (-51.28%)
Mutual labels:  hal
skynet robot control rtos ethercat
Realtime 6-axis robot controller, based on Qt C++ & OpenCascade & KDL kinematics & HAL
Stars: ✭ 41 (+5.13%)
Mutual labels:  hal
halfred
A parser for application/hal+json
Stars: ✭ 44 (+12.82%)
Mutual labels:  hal
hal-client
A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.
Stars: ✭ 21 (-46.15%)
Mutual labels:  hal
bxcan
bxCAN peripheral driver for STM32 chips
Stars: ✭ 22 (-43.59%)
Mutual labels:  hal
ng-hal
A navigator for HAL documents in Angular
Stars: ✭ 24 (-38.46%)
Mutual labels:  hal
bowman
A Java library for accessing a JSON+HAL REST API
Stars: ✭ 45 (+15.38%)
Mutual labels:  hal
Eqmac
macOS System-wide Audio Equalizer & Volume Mixer 🎧
Stars: ✭ 3,947 (+10020.51%)
Mutual labels:  hal
console
HAL management console
Stars: ✭ 41 (+5.13%)
Mutual labels:  hal
STM32 HAL FREEMODBUS RTU
FreeMODBUS RTU port for STM32 HAL library
Stars: ✭ 111 (+184.62%)
Mutual labels:  hal
gsm
gsm module library for STM32 LL
Stars: ✭ 28 (-28.21%)
Mutual labels:  hal
laravel5-hal-json
Laravel 5 HAL+JSON API Transformer Package
Stars: ✭ 15 (-61.54%)
Mutual labels:  hal
HAL-Webinar
Webinar – Creating a Hardware Abstraction Layer in LabVIEW
Stars: ✭ 22 (-43.59%)
Mutual labels:  hal
HX711
HX711 driver for STM32 HAL
Stars: ✭ 34 (-12.82%)
Mutual labels:  hal
mezzio-hal
Hypertext Application Language implementation for PHP and PSR-7
Stars: ✭ 19 (-51.28%)
Mutual labels:  hal
akka-http-hal
HAL (Hypermedia Application Language) specification support for akka-http
Stars: ✭ 18 (-53.85%)
Mutual labels:  hal
php-hal
HAL+JSON & HAL+XML API transformer outputting valid (PSR-7) API Responses.
Stars: ✭ 30 (-23.08%)
Mutual labels:  hal
Core
The server component of API Platform: hypermedia and GraphQL APIs in minutes
Stars: ✭ 2,004 (+5038.46%)
Mutual labels:  hal
hal-api
Enhances your HATEOAS experience by automating common tasks.
Stars: ✭ 32 (-17.95%)
Mutual labels:  hal
MPU6050
STM32 HAL library for GY-521 (MPU6050) with Kalman filter
Stars: ✭ 114 (+192.31%)
Mutual labels:  hal

Curveball Browser

This package provides a middleware that automatically turns JSON responses from an API into HTML responses.

It will do so by looking if the API was accessed by a HTTP client that prefers HTML. Browsers do this by sending an Accept: text/html header.

If this middleware spots this, it will kick in and auto-generate a great looking HTML document.

If this header was not provides, this middleware does nothing.

It automatically decorates the following formats:

  • application/json
  • application/problem+json
  • application/hal+json
  • text/markdown
  • text/csv
  • application/prs.hal-forms+json
  • application/vnd.siren+json

Screenshot

An example. If an API normally returns the following HAL format:

{
  "_links": {
    "self": { "href": "/testing" },
    "previous": {
      "href": "/testing/?page=1",
      "title": "Previous page"
    },
    "next": {
      "href": "/testing/?page=2",
      "title": "Next page"
    },
    "author": {
      "href": "https://evertpot.com",
      "title": "Evert Pot"
    },
    "help": {
      "href": "https://google.com/",
      "title": "Google it"
    },
    "search": {
      "href": "https://google.com/{?q}",
      "templated": true
    },
    "edit": { "href": "/testing" },
    "create-form": { "href": "/testing" },
    "my-link": {
      "href": "/foo-bar",
      "title": "Custom link"
    },
    "alternate": [
      {
        "href": "/testing/markdown",
        "type": "text/markdown",
        "title": "Markdown test"
      },
      {
        "href": "/testing/csv",
        "type": "text/csv",
        "title": "Csv test"
      },
      {
        "href": "/testing/rss",
        "type": "application/rss+xml",
        "title": "RSS"
      },
      {
        "href": "/testing/rss",
        "type": "application/atom+xml",
        "title": "Atom"
      }
    ],
    "code-repository": { "href": "https://github.com/evert/hal-browser" },
    "redirect-test": { "href": "/redirect-test" }
  },
  "msg": "Hello world!",
  "version": "0.5.0",
  "name": "test resource!"
}

The browser will automatically convert it to this HTML format:

Screenshot from 0.9.1

This screenshot is an example of the browser automatically formatting a .csv and parsing HTTP Link headers:

Screenshot from 0.9.1

The following example converts this:

{
  "_links": {
    "self": {
      "href": "/testing/form"
    },
    "up": {
      "href": "/testing",
      "title": "Back to testing home"
    },
    "my-form": {
      "href": "/testing/form{?startDate}{?endDate}",
      "title": "Search by date range",
      "templated": true
    }
  }
}

And automatically turns the templated link into a form:

Screenshot from 0.9.1

Installation

npm install @curveball/browser

Getting started

import { Application } from 'curveball/@core';
import browser from '@curveball/browser';

const app = new Application();
app.use(browser({}));

Options

The halBrowser function takes an options object, which can take the following settings:

  • title - Change the main title.
  • theme - curveball by default, but lfo and spicy-oj are also provided.
  • stylesheets - Provide your own stylesheets. This is an array of strings. these are relative urls, and they are automatically expanded based on the assetBaseUrl 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 to false.
  • defaultLinks - A list of links that will show up by default, whether or not they were specified by the API. By default a home 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'].
  • fullBody - If turned on, full JSON bodies are always rendered. This can also be turned on during runtime by adding a ?_browser-fullbody query parameter.
  • allLinks - By default the Browser will hide links from the 'Links' table that will be rendered as 'navigation buttons', forms (templated links), or are considered special (the 'self' link). While this might be a nicer interface for an average user browsing the hypermedia graph, as a developer you might just want to see all the links.

Example:

app.use(browser({
  title: 'My API',
  stylesheets: [
    '/my-stylesheet.css',
  ],

  // This should end with a / generally.
  assetBaseUrl: 'http://some-cdn.example.org/',

  navigationLinks: {
    // Create new 'author' button
    'author' : {
      // optional css class, by default this will be `rel-author`
      cssClass: 'rel-blabla',

      // Optional title to show when hovering over button
      defaultTitle: 'Click me',

      // Override icon. Also optional
      icon: 'icons/foobar.svg',

      // Either 'header' (default) or 'pager'
      position: 'header'

      // Set the order. Lower is earlier. Default is 0.
      priority: -100,

    },
    // passing 'true' will use default setting for the button
    'help' : true,

    // passing 'null' will remove the icon, if it was a default icon
    'up': null,
  },

  defaultLinks: [
    // Every page will have a 'help' link
    {
      rel: 'help',
      href: 'https://example.org/help',
      title: 'Support',
    }
  ],
});

Future features

  • Add a link to allow the user to see the raw format.
  • Show metadata, such as Last-Modified
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].