curveball / core

The Curveball framework is a TypeScript framework for node.js with support for modern HTTP features.
https://curveballjs.org/
MIT License
525 stars 7 forks source link

Adding a links object on both the request and response. #124

Closed evert closed 3 years ago

evert commented 4 years ago

This is kind of an experimental approach. Shouldn't merge this until it had some more testing (and is fully covered with unittests).

The goal of this feature is to have a unified way to access Web Links via a simple API, whether that's links in a HTTP Link header, or embedded in a body.

If links are embedded in a body, middlewares should be written to automatically read and/or write them.

Sample usage:

const link = ctx.request.links.get('author');

ctx.response.links.set({
  rel: 'author',
  href: 'https://evertpot.com/',
  type: 'text/html',
  position: 'header', // or body
});

Right now I'm just looking for some feedback about this specific approach.

evert commented 3 years ago

All the features of this PR have been implemented as a middleware:

https://github.com/curveball/links/