Socket
Book a DemoInstallSign in
Socket

restify-links

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify-links

Middleware that adds the res.links function from Express to Restify responses objects.

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
6
20%
Maintainers
2
Weekly downloads
 
Created
Source

Middleware that adds the res.links function from Express to Restify responses objects.

Usage

Join the given links to populate the "Link" response header field.

res.links({
    next: 'http://api.example.com/users?page=2',
    last: 'http://api.example.com/users?page=5'
});

yields:

Link: <http://api.example.com/users?page=2>; rel="next", 
      <http://api.example.com/users?page=5>; rel="last"

This library also works for link definition objects and arrays, allowing one to construct significantly more complex and descriptive link relations. You can mix and match as needed, plus keep adding to the list of links.

res.links({
    next: "http://api.example.com/users?page=2",
    self: "http://api.example.com/users",
    search: "http://api.example.com/users{?username,firstname,lastname}"
});
res.links({
    last: "http://api.example.com/users?page=5",
    stylesheet: {
        href: "http://static.example.com/ss.css",
        type: "text/css"
    },
    up: [
        "http://api.example.com/"
    ],
    service: [
        {
            href: "https://api.example.com/auth",
            method: "post",
            profile: "/schemas/auth",
            title: "auth"
        }
    ]
});

results in:

Link: <http://api.example.com/users>; rel="self",
      <http://api.example.com/users?page=2>; rel="next",
      <http://api.example.com/users{?username,firstname,lastname}>; rel="search",
      <http://api.example.com/users?page=5>; rel="last",
      <http://static.example.com/ss.css>; rel="stylesheet"; type="text/css",
      <http://api.example.com/>; rel="up",
      <https://api.example.com/auth>; rel="service"; method="post"; profile="/schemas/auth"; title="auth"

This greatly assists with working with REST level 3 (Hypermedia) APIs and making the resources self-describing. In fact, the link definition objects are compatible with JSON Schema for Hypermedia and HAL Link Objects. It can use the link-extension part of the Web Linking specification.

Keywords

restify

FAQs

Package last updated on 06 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.