Skip to content

richardschneider/express-prefer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-prefer Build Status

RFC 7240 defines an HTTP header field that can be used by a client to request that certain behaviors be employed by a server while processing a request.

This package parses the HTTP Request and makes the prefer headers a keyed property of req.prefer.

Getting started npm version

$ npm install express-prefer --save

then add to your server.js file

app.use(require('express-prefer'))

and That's all folks!

Usage

Given the following Request

PATCH /my-document HTTP/1.1
Host: example.org
Content-Type: application/json-patch+json
Prefer: return=representation

[{"op": "add", "path": "/a", "value": 1}]

then

app.patch('/:doc', (req,res,next) => {
    // Apply the patch ...
    
    // What should we return?
    if (req.prefer.return == 'representation')
        res.status(200).send(doc).end();
    else
        res.status(204).end();
})

License

The MIT license

Copyright © 2015 Richard Schneider ([email protected])

About

RFC 7240 - Prefer Header for HTTP

Resources

License

Stars

Watchers

Forks

Packages

No packages published