Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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.
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);
});
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Compared to Restify, Express is more general-purpose and widely used for a variety of web applications, not just RESTful APIs.
Hapi is a rich framework for building applications and services in Node.js. It is known for its powerful plugin system and configuration-based approach. Hapi offers more built-in features and a different approach to configuration and extensibility compared to Restify.
Koa is a new web framework designed by the team behind Express, aiming to be a smaller, more expressive, and more robust foundation for web applications and APIs. Koa uses async functions to eliminate callback hell and improve error handling, offering a more modern approach compared to Restify.
restify is a framework, utilizing connect style middleware for building REST APIs. For full details, see http://restify.com
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);
});
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);
});
$ npm install restify
Restify currently works on Node.js v14.x and v16.x.
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.
See https://github.com/restify/node-restify/issues.
See the Google group .
FAQs
REST framework
The npm package restify receives a total of 262,357 weekly downloads. As such, restify popularity was classified as popular.
We found that restify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.