Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

restify

restify1.1mMIT11.1.0TypeScript support: definitely-typed

REST framework

REST, framework, express, DTrace

readme

alt text

restify

Build Status Dependency Status devDependency Status code style: prettier

restify is a framework, utilizing connect style middleware for building REST APIs. For full details, see http://restify.com

Follow restify on alt text

Usage

Server

var restify = require('restify');

const server = restify.createServer({
  name: 'myapp',
  version: '1.0.0'
});

server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());

server.get('/echo/:name', function (req, res, next) {
  res.send(req.params);
  return next();
});

server.listen(8080, function () {
  console.log('%s listening at %s', server.name, server.url);
});

Client

var assert = require('assert');
var clients = require('restify-clients');

var client = clients.createJsonClient({
  url: 'http://localhost:8080',
  version: '~1.0'
});

client.get('/echo/mark', function (err, req, res, obj) {
  assert.ifError(err);
  console.log('Server returned: %j', obj);
});

Installation

$ npm install restify

Supported Node Versions

Restify currently works on Node.js v14.x and v16.x.

License

The MIT License (MIT)

Copyright (c) 2018 restify

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bugs

See https://github.com/restify/node-restify/issues.

Other repositories

  • For the errors module, please go here.

Mailing list

See the Google group .

changelog

9.0.0 (2022-11-15)

⚠ BREAKING CHANGES

  • remove deprecated usage of pino.child (#1902)
  • deprecates and removes re-routing when passing a string parameter to next()
  • removes RequestCaptureStream and replaces Bunyan with Pino
  • adds async/await support to pre, use and handler chains
  • drops suppoprt to node 8 and updates linting rules
  • server: - Server returns RequestCloseError instead of RequestAbortedError
  • travisci: dropping support below Node.js 4

Features

  • async/await support (12be9e2)
  • deprecate req.closed (d052b7c)
  • provide callback to uncaughtException handler (#1766) (5e8b5e2)
  • remove re-routing from handler (#1847) (9153587)
  • send 500s for unhandled requests (#1777) (885cecd)
  • audit: Add the ability to specify a custom audit log serializer (for err, req and res) (#1746) (6231acd)
  • chain: schedule handlers to the next tick (#1798) (806ed71)
  • chain: use nextTick instead of setImmediate (#1808) (703470a)
  • deps: replace cover/istanbul with nyc (#1823) (361f83e)
  • first: Handlers that execute ASAP in the req/res lifecycle (#1756) (8178098)
  • http2: add native HTTP/2 support (#1489) (6b20285)
  • plugin: plugin to serve static files (#1753) (a67b25f)
  • Ability to find a route by a path (711a489)
  • add router.render() back to support hypermedia usecase (#1752) (0700cfd), closes #1684
  • helpers: add compose feature (#1660) (eb60ef4)
  • plugins: context, req.get() returns the whole context (#1739) (6e35e01)
  • plugins: do not include user-input in UnsupportedMediaTypeError message (VError fails), move it to info (#1733) (06c220d)
  • req: add restifyDone event (#1740) (4900d6b)
  • add support for non-strict formatters (#1721) (de1833a)
  • jsonBodyParser handles extended content types *+json (#1663) (4537514)
  • router: add ignoreTrailingSlash router option (#1632) (92ffbf5)
  • server: new router and middleware system (#1561) (8283277)
  • cpuUsageThrottle (#1460) (84be679)
  • throttle plugin: expose rate limit metrics as headers (#1453) (1627a55)
  • create inflightRequestThrottle plugin (#1431) (285faf4)
  • revert async formatters (#1377) (a2e300f)

Bug Fixes

  • add support for secureOptions in createServer (#1575) (656e60e)
  • Allow multiple unmerged set-cookie headers. (#1570) (df04015)
  • Correct typo in assertion message (#1904) (195cf13)
  • documentation typo fix (#1688) (0fa7132)
  • don't create empty clientError listener for http.Server (#1895) (ddc1042)
  • emit after event with proper error param for node versions >= 11.4.0 (#1732) (7a1378b)
  • examples/todoapp/package.json to reduce vulnerabilities (#1832) (d9b27c6)
  • format falsy constants properly in json formatter (#1792) (3002182)
  • make arity error message actionable (#1901) (97b6f93)
  • more flaky metrics.test.js fixes (#1730) (71aac42)
  • properly handle non-errors thrown in domains (#1757) (cb2e717)
  • proxy events into instance var and add test script (#1661) (de72f49)
  • Re-add support for clientError listeners (#1897) (05f12a6)
  • remove invalid triggering of uncaughtException handler (#1710) (ee69806)
  • Return 444 status code for closed and aborted requests (#1579) (644c198)
  • send numbers or bools as payloads (#1609) (0919f26)
  • server should fire not acceptable event (#1627) (8b11b71)
  • use close event on response instead of socket (#1892) (5c7eb95)
  • use more reliable close event (36318ae)
  • benchmark: force latest restify version (#1810) (b8ec60e)
  • bodyReader: Fix memory leak (#1566) (756b3f0)
  • cpuUsageThrottle: Always queue a new timeout (#1484) (e4ffe43)
  • cpuUsageThrottle: Correctly named handler for debugInfo (#1499) (78b0900)
  • cpuUsageThrottle: dont include interval in lag (#1504) (eecb2d2)
  • cpuUsageThrottle: support breaking change in pidusage module (7460064)
  • dev: pin to exact versions of linting tools and fix lint errors (3740a6b)
  • dev: remove nsp since the project merged with npm (1dc34b4)
  • dev: upgrading modules including restify-errors (#1755) (3b71229)
  • dtrace: route probes (#1659) (84bcded)
  • inflightRequestThrottle: properly handle next (#1471) (4db404f)
  • jsonBodyParser: fix percent sign causing server fail (#1411) (bde8fda)
  • npm: exclude extraneous files (#1818) (e8516c3)
  • npm: remove unleash dependency (#1522) (a43aa60)
  • package-lock.json: remove artifacts.netflix.com repo (#1526) (3d2f0f7)
  • plugins: save req._matchedVersion (#1642) (69f917a)
  • plugins: use process.hrtime() for duration calculation (#1507) (e8efd6c)
  • request: date() and time() methods return value (#1576) (4c2cb1a)
  • server: address domain performance regression with Node v12.x (#1809) (e648d49)
  • server: address req and res close event changes in Node v10.x (#1672) (6be3fb7)
  • server: avoid http2 experimental warning without http2 option (#1555) (12da7fd)
  • server: avoiding uncaughtException in _routeErrorResponse by only sending response when not sent (#1568) (cf65c65)
  • server: fix uncaught exceptions triggering route lookups (#1717) (e49cb3b)
  • test: make upgrade test pass (#1772) (d30b748)
  • 652 - Incorrect error on route with no versions (#1465) (ee15490)
  • Add migration guid to website (#1402) (5f053c7)
  • add node 7-8 travis support (#1405) (536a473)
  • create unit tests for sanitizePath plugin (#1352) (12714cf)
  • doc site (#1393) (76ee548)
  • documentation update for restifyError event example (#1398) (94fe715)
  • emit restifyError event even for router errors (#1420) (f9d02d5)
  • redirect should work even when hostname or protocol is not specified in req.url (#1497) (e696a1f)
  • server: error in pre handler triggers after event (#1500) (c2e6dea)
  • exclude package-lock.json (#1477) (011fdf0)
  • static: avoid user-provided data in Error messages being interpreted as sprintf codes (#1384) (#1472) (9906344)
  • audit timers of same name should accumulate (#1435) (#1443) (a2d34aa)
  • GH-1438, error reponse customization documentation incorrect (#1439) (dd66088)
  • Honor port for redirect (#1363) (61c0cb5)
  • monkey patch getHeaders for pre-v7 Node.js (GH-1409) (82088a7)
  • package.json version now matches npm (9944dbd)
  • respect when status code is set with res.status (GH-1429) (#1440) (5abc067)
  • test static plugin's handling of sprintf escape sequences (#1391) (5d7039a)
  • update chai (^3.4.1 to ^4.0.0) (f982d0c)
  • Update dependency mime to 1.4.0 (#1467) (6d38b38)
  • update http-signature to v1.0.0 (#1401) (ec88737)
  • use Buffer.isBuffer instead of util.isBuffer. (#1593) (35bd1c2)
  • versioned route matching should not throw TypeError (#1381) (25d10f0)
  • audit: use public APIs for accessing response headers (5169db7), closes /nodejs.org/api/deprecations.html#deprecations_dep0066
  • Prefer Pino logger over Bunyan (#1841) (2f5bf87), closes #1841

Miscellaneous Chores

  • drop support for node 8 (bd34988)
  • remove deprecated usage of pino.child (#1902) (0a8cf83)
  • travisci: revisit nodejs version. Change to: LTS active, LTS maintenance (4.x) and stable releases (#1553) (49eb008)

11.1.0 (2023-02-24)

Features

  • allow custom alternatives to domains (54adfcb)

11.0.0 (2023-01-17)

⚠ BREAKING CHANGES

  • don't override req.log if set during .first
  • use req.log on audit plugin

Features

  • don't override req.log if set during .first (852d2c1)
  • use req.log on audit plugin (528ecbc)

10.0.0 (2022-11-29)

⚠ BREAKING CHANGES

  • support v18.x

Features

  • bump dtrace-provider version to avoid MacOS errors (fa52f60)
  • support v18.x (5795223)

8.5.1 (2019-12-13)

Bug Fixes

  • benchmark: force latest restify version (#1810) (b8ec60e3)
  • server: address domain performance regression with Node v12.x (#1809) (e648d491)

8.5.0 (2019-12-02)

Features

  • chain: use nextTick instead of setImmediate (#1808) (703470ad)

8.4.1 (2019-11-27)

8.4.0 (2019-07-31)

Features

  • chain: schedule handlers to the next tick (#1798) (806ed711)

8.3.3 (2019-06-04)

8.3.2 (2019-05-06)

8.3.1 (2019-04-25)

Bug Fixes

  • test: make upgrade test pass (#1772) (d30b7483)

8.3.0 (2019-04-11)

Features

  • provide callback to uncaughtException handler (#1766) (5e8b5e2b)

8.2.0 (2019-03-18)

Bug Fixes

  • properly handle non-errors thrown in domains (#1757) (cb2e7177)
  • cpuUsageThrottle: support breaking change in pidusage module (7460064f)

Features

  • first: Handlers that execute ASAP in the req/res lifecycle (#1756) (8178098d)

8.1.1 (2019-03-14)

Bug Fixes

  • Published NPM package had a bad dependency on npm causing new irrelevant packages to get installed

8.1.0 (2019-03-06)

Bug Fixes

  • dev: upgrading modules including restify-errors (#1755) (3b712298)

Features

  • add router.render() back to support hypermedia usecase (#1752) (0700cfd4, closes #1684)
  • plugin: plugin to serve static files (#1753) (a67b25f4)

8.0.0 (2019-02-20)

Breaking Changes

  • Dropped Support for Node v4.x and Node v6.x

7.7.0 (2019-02-01)

Bug Fixes

  • dev:
    • remove nsp since the project merged with npm (1dc34b48)
    • pin to exact versions of linting tools and fix lint errors (3740a6b7)

Features

  • audit: Add the ability to specify a custom audit log serializer (for err, req and res) (6231acda)

7.6.0 (2019-01-18)

Features

  • req: add restifyDone event (#1740) (4900d6bd)

7.5.0 (2019-01-09)

Bug Fixes

  • emit after event with proper error param for node versions >= 11.4.0 (#1732) (7a1378b0)

Features

  • plugins: context, req.get() returns the whole context (#1739) (6e35e01e)

7.4.0 (2019-01-02)

Bug Fixes

  • more flaky metrics.test.js fixes (#1730) (71aac428)

Features

  • plugins: do not include user-input in UnsupportedMediaTypeError message (VError fails), m (06c220d2)

7.3.0 (2018-12-07)

Features

  • add support for non-strict formatters (#1721) (de1833a4)

7.2.3 (2018-11-16)

Bug Fixes

  • server: fix uncaught exceptions triggering route lookups (#1717) (e49cb3b2)

7.2.2 (2018-10-29)

Bug Fixes

  • documentation typo fix (#1688) (0fa71328)

7.2.1 (2018-06-07)

Bug Fixes

  • proxy events into instance var and add test script (#1661) (de72f49e)
  • server: address req and res close event changes in Node v10.x (#1672) (6be3fb7c)

Features

  • jsonBodyParser handles extended content types *+json (#1663) (45375144)

7.2.0 (2018-05-16)

Features

  • helpers: add compose feature (#1660) (eb60ef40)

7.1.2 (2018-05-15)

Bug Fixes

  • dtrace: route probes (#1659) (84bcded7)

7.1.1 (2018-04-10)

Bug Fixes

  • plugins: save req._matchedVersion (#1642) (69f917a3)

7.1.0 (2018-03-26)

Features

  • router: add ignoreTrailingSlash router option (#1632) (92ffbf5c)

7.0.0 (2018-03-20)

Features

  • server: new router and middleware system (#1561) (1161370b)

Breaking Changes

*

  • Server returns RequestCloseError instead of RequestAbortedError
  • Non-strict routing is gone
  • Different RegExp usage in router path and wildcards
  • Remove already deprecated next.ifError
  • Disable DTrace probes by default
  • Change in calling next multiple times
  • Router versioning and content type as a separate plugin: conditionalHandler
  • After event fires when both request is flushed and the last handler is finished
  • Metrics plugin latency logic changes and new latencies were added

For more info see the /guides/6to7guide.md. (1161370b)

  • dropping support below Node.js 4 (0698f45c)

6.4.0 (2018-03-20)

Bug Fixes

  • server should fire not acceptable event (#1627) (8b11b71b)
  • send numbers or bools as payloads (#1609) (0919f26d)
  • Allow multiple unmerged set-cookie headers. (#1570) (df040154)
  • add support for secureOptions in createServer (#1575) (656e60e0)
  • use Buffer.isBuffer instead of util.isBuffer. (#1593) (35bd1c2b)
  • jsonBodyParser: fix percent sign causing server fail (#1411) (bde8fda6)
  • request: date() and time() methods return value (#1576) (4c2cb1a7)

6.3.4 (2017-11-21)

Bug Fixes

  • bodyReader: Fix memory leak (#1566) (756b3f02)
  • server: avoiding uncaughtException in _routeErrorResponse by only sending response when (cf65c65c)

6.3.2 (2017-11-08)

6.3.1 (2017-11-03)

Bug Fixes

  • server: avoid http2 experimental warning without http2 option (#1555) (12da7fdf)

6.3.0 (2017-11-02)

Features

  • http2: add native HTTP/2 support (#1489) (6b202853)

6.2.3 (2017-10-18)

6.2.2 (2017-10-18)

Bug Fixes

  • package-lock.json: remove artifacts.netflix.com repo (#1526) (3d2f0f7d)

6.2.1 (2017-10-18)

Bug Fixes

  • cpuUsageThrottle: dont include interval in lag (#1504) (eecb2d25)
  • npm: remove unleash dependency (#1522) (a43aa60f)
  • plugins: use process.hrtime() for duration calculation (#1507) (e8efd6cd)

6.2.0 (2017-10-16)

Bug Fixes

  • cpuUsageThrottle: dont include interval in lag (#1504) (eecb2d25)
  • plugins: use process.hrtime() for duration calculation (#1507) (e8efd6cd)

6.1.0 (2017-10-16)

Bug Fixes

  • cpuUsageThrottle: dont include interval in lag (#1504) (eecb2d25)
  • plugins: use process.hrtime() for duration calculation (#1507) (e8efd6cd)

6.0.1 (2017-09-19)

Bug Fixes

  • cpuUsageThrottle: Correctly named handler for debugInfo (#1499) (78b0900b)
  • server: error in pre handler triggers after event (#1500) (c2e6deae)

6.0.0 (2017-09-15)

Bug Fixes

  • exclude package-lock.json (#1477) (011fdf0e)
  • Update dependency mime to 1.4.0 (#1467) (6d38b38c)
  • cpuUsageThrottle: Always queue a new timeout (#1484) (e4ffe430)
  • inflightRequestThrottle: properly handle next (#1471) (4db404f9)
  • static: avoid user-provided data in Error messages being interpreted as sprintf codes (# (99063447)

Features

  • cpuUsageThrottle (#1460) (84be6799)
  • throttle plugin: expose rate limit metrics as headers (#1453) (1627a557)

5.2.0 (2017-08-16)

Bug Fixes

  • package.json version now matches npm (9944dbd5)
  • create unit tests for sanitizePath plugin (#1352) (12714cfc)
  • audit timers of same name should accumulate (#1435) (#1443) (a2d34aaa)
  • respect when status code is set with res.status (GH-1429) (#1440) (5abc0677)
  • versioned route matching should not throw TypeError (#1381) (25d10f00)

5.0.1 (2017-07-17)

Bug Fixes

  • monkey patch getHeaders for pre-v7 Node.js (GH-1409) (82088a71)
  • add node 7-8 travis support (#1405) (536a4735)
  • Add migration guid to website (#1402) (5f053c7e)
  • update http-signature to v1.0.0 (#1401) (ec887376)
  • documentation update for restifyError event example (#1398) (94fe7151)
  • doc site (#1393) (76ee5480)
  • test static plugin's handling of sprintf escape sequences (#1391) (5d7039a5)