API include functionality middleware

Usage no npm install needed!

<script type="module">
  import restifyInclude from '';



Simple middleware for restify (probably compatible with many other libraries as well) that adds the include query behavior to your API.

Let's say a random API request to has the following data:

  id: 123,
  name: 'Model S',
  manufacturer_id: 'tesla',
  manufacturer_url: ''

Now with the include middleware, you can do and the middleware will automatically for you, request the manufacturer object for you (following the url above) and include it in the reponse:

  id: 123,
  name: 'Model S',
  manufacturer_id: 'tesla',
  manufacturer_url: '',
  manufacturer: {
    id: 'tesla',
    name: 'Tesla'

How it works

The middleware checks for the query parameter include. If a url for the field(s) specified in the include parameter exists in the response object (<fieldName>_url), a request to that url is made and the results embeded in the response.


var include = require('node-restify-include');

// create server here

server.use(include()); //Add the middleware


The middleware defaults includes the authorization header from the original request. You can also ask it to include any other headers from the original request like so:

//Make the middleware forward the following headers from the original request.
  headers: ['authorization', 'user-agent', 'x-request-id']