Socket
Socket
Sign inDemoInstall

restify

Package Overview
Dependencies
Maintainers
6
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify

REST framework


Version published
Weekly downloads
139K
increased by23.77%
Maintainers
6
Weekly downloads
 
Created

What is restify?

Restify is a Node.js web service framework optimized for building RESTful APIs. It is designed to be lightweight and efficient, making it ideal for creating scalable and high-performance web services.

What are restify's main functionalities?

Creating a Basic Server

This code demonstrates how to create a basic Restify server that listens on port 8080 and responds with 'Hello, world!' when a GET request is made to the '/hello' endpoint.

const restify = require('restify');
const server = restify.createServer();

server.get('/hello', (req, res, next) => {
  res.send('Hello, world!');
  next();
});

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

Middleware Support

This example shows how to use middleware in Restify. The bodyParser plugin is used to parse the body of incoming POST requests, and the server responds with the parsed body.

const restify = require('restify');
const server = restify.createServer();

server.use(restify.plugins.bodyParser());

server.post('/data', (req, res, next) => {
  res.send(req.body);
  next();
});

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

Error Handling

This code demonstrates how to handle errors in Restify. When a GET request is made to the '/error' endpoint, an InternalServerError is thrown. The 'restifyError' event is used to log the error and send an appropriate response.

const restify = require('restify');
const server = restify.createServer();

server.get('/error', (req, res, next) => {
  return next(new restify.errors.InternalServerError('Something went wrong!'));
});

server.on('restifyError', (req, res, err, callback) => {
  console.error(err);
  res.send(err);
  return callback();
});

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

Other packages similar to restify

FAQs

Package last updated on 10 Feb 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc