
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
angular-rest
Advanced tools
AngularJS $resource bindings for express (Previously known as angular-resource)
AngularJS $resource bindings for express in node
angular-rest is a node module that simplifies the use of angularjs $resource factory by creating the default set of resource actions for get, save, query, remove and delete.
It is best described by example. Suppose you have an angularjs service defined as follows:
var myServices = angular.module('myServices', ['ngResource'])
myServices.factory('Task', function($resource) {
return $resource('api/tasks/:id', { id: "@_id" });
});
The myServices Task will, by default, now support get, save, query, remove and delete. The required endpoints can simply be routed via express by using the angular-rest module:
First create a task.js with the following details:
var task = { };
task.get = function(req, res) {
res.json({});
};
task.save = function(req, res) {
res.send(200);
};
task.query = function(req, res) {
res.json([]);
};
task.remove = function(req, res) {
res.send(200);
};
module.exports = task;
and then use angular-rest to bind it into express.
var angularRest = require('angular-rest'),
express = require('express');
var app = express();
angularRest(app, '/api/1', 'task');
app.listen(3000);
This will bind the required endpoints through to task.js. Note that both 'delete' and 'remove' are routed to the 'remove' method.
If you wish to use middleware, then define the binding as follows:
var middleware = function(req, res, next) {
return next(req, res);
};
angularRest(app, '/api/1', 'task', middleware);
If you don't want to support all of the default $resource actions, then just omit them from the object. In the example above, if you don't want to support remove then just define task.js as follows:
var task = { };
task.get = function(req, res) {
res.json({});
};
task.save = function(req, res) {
res.send(200);
};
task.query = function(req, res) {
res.json([]);
};
module.exports = task;
You can now create includes for all of the $resource objects your angularjs services require and bind them in the same way.
FAQs
AngularJS $resource bindings for express (Previously known as angular-resource)
The npm package angular-rest receives a total of 1 weekly downloads. As such, angular-rest popularity was classified as not popular.
We found that angular-rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.