@curveball/links

1.0.1 • Public • Published

Curveball Links middleware

This Curveball middleware helps you parse and generate HTTP Weblinks.

Any links passed in a request via the Link header will now be exposed in ctx.request. Similarly, if a link was set in ctx.response.links, it will automatically be encoded as a Link header in the HTTP response.

Lastly, if the request body was a HAL object, and it has a _links property, these links will also be added to ctx.response.links.

Installation

npm i @curveball/links

Usage

import { Application, Context } from '@curveball/core';
import links from '@curveball/links';
import bodyParser from '@curveball/bodyparser';


const app = new Application();

// If you would like to parse HAL links, the bodyParser must be loaded first.
app.use(bodyParser());

app.use(links());

app.use( (ctx: Context) => {

  // Read a Link from a HAL body or Link header
  console.log(ctx.request.links.get('author'));

  // Write a Link header
  ctx.response.links.set({ rel: 'alternate' , type: 'text/csv', href: '/export.csv'});

});

Package Sidebar

Install

npm i @curveball/links

Weekly Downloads

107

Version

1.0.1

License

MIT

Unpacked Size

17.2 kB

Total Files

24

Last publish

Collaborators

  • evrt
  • mihok
  • juhangsin
  • beckypollard