Socket
Socket
Sign inDemoInstall

express-resource

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-resource - npm Package Compare versions

Comparing version 0.2.4 to 1.0.0

examples/controllers.js

55

examples/content-negotiation.js
require.paths.unshift(__dirname + '/../support');
/**
* Module dependencies.
*/
var express = require('express')
, resource = require('../')
, app = express.createServer();
, resource = require('..')
, app = express();
var db = ['tobi', 'loki', 'jane']
, toys = ['ball', 'tunnel'];
var users = app.resource('users', require('./controllers/user'));
var pet = {
index: {
json: function(req, res){
res.send(db);
},
default: function(req, res){
res.send(db.join(', '), { 'Content-Type': 'text/plain' });
}
}
};
var pets = app.resource('pets', pet);
pets.load(function(id, fn){
fn(null, db[id]);
app.get('/', function(req, res){
res.send('<a href="/users">View users</a>');
});
// GET /pets/toys.xml
// this action must be defined above
// the one below as the :pet placeholder
// will otherwise match "/toys".
pets.get('/toys', {
xml: function(req, res){
res.send('<toys>' + toys.map(function(toy){
return '<toy>' + toy + '</toy>';
}).join('\n') + '</toys>');
}
});
// GET /pets/1.xml
pets.get({
xml: function(req, res){
res.send('<pet>' + req.pet + '</pet>');
}
});
app.listen(3000);
app.listen(3000);
console.log('Listening on :3000');
1.0.0 / 2012-10-06
==================
* add 3x support... Closes #55
0.2.4 / 2011-12-28

@@ -3,0 +8,0 @@ ==================

/*!
* Express - Resource
* Copyright(c) 2010-2011 TJ Holowaychuk <tj@vision-media.ca>
* Copyright(c) 2010-2012 TJ Holowaychuk <tj@vision-media.ca>
* Copyright(c) 2011 Daniel Gasienica <daniel@gasienica.ch>

@@ -14,3 +14,6 @@ * MIT Licensed

var express = require('express')
, methods = require('methods')
, debug = require('debug')('express-resource')
, lingo = require('lingo')
, app = express.application
, en = lingo.en;

@@ -23,12 +26,18 @@

var orderedActions = [
'index' // GET /
,'new' // GET /new
,'create' // POST /
,'show' // GET /:id
,'edit' // GET /edit/:id
,'update' // PUT /:id
,'destroy' // DEL /:id
'index' // GET /
, 'new' // GET /new
, 'create' // POST /
, 'show' // GET /:id
, 'edit' // GET /edit/:id
, 'update' // PUT /:id
, 'destroy' // DEL /:id
];
/**
* Expose `Resource`.
*/
module.exports = Resource;
/**
* Initialize a new `Resource` with the given `name` and `actions`.

@@ -42,3 +51,3 @@ *

var Resource = module.exports = function Resource(name, actions, app) {
function Resource(name, actions, app) {
this.name = name;

@@ -55,3 +64,3 @@ this.app = app;

// default actions
for (var i=0, key; i < orderedActions.length; i++) {
for (var i = 0, key; i < orderedActions.length; ++i) {
key = orderedActions[i];

@@ -150,10 +159,8 @@ if (actions[key]) this.mapDefaultAction(key, actions[key]);

req.format = req.params.format || req.format || self.format;
if (req.format) res.contentType(req.format);
if (req.format) res.type(req.format);
if ('object' == typeof fn) {
if (req.format && fn[req.format]) {
if (fn[req.format]) {
fn[req.format](req, res, next);
} else if (fn.default) {
fn.default(req, res, next);
} else {
res.send(406);
res.format(fn);
}

@@ -193,3 +200,8 @@ } else {

delete routes[key];
app[method](key).remove();
if (method == 'del') method = 'delete';
app.routes[method].forEach(function(route, i){
if (route.path == key) {
app.routes[method].splice(i, 1);
}
})
resource.map(route.method, route.orig, route.fn);

@@ -240,3 +252,3 @@ }

express.router.methods.concat(['del', 'all']).forEach(function(method){
methods.concat(['del', 'all']).forEach(function(method){
Resource.prototype[method] = function(path, fn){

@@ -259,4 +271,3 @@ if ('function' == typeof path

express.HTTPServer.prototype.resource =
express.HTTPSServer.prototype.resource = function(name, actions, opts){
app.resource = function(name, actions, opts){
var options = actions || {};

@@ -263,0 +274,0 @@ if ('object' == typeof name) actions = name, name = null;

@@ -1,20 +0,36 @@

{ "name": "express-resource"
, "description": "Resourceful routing for express"
, "version": "0.2.4"
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
, "contributors": [
{ "name": "Daniel Gasienica", "email": "daniel@gasienica.ch" }
]
, "dependencies": { "lingo": ">= 0.0.4" }
, "devDependencies": {
"connect": "1.8.x"
, "express": "2.5.x"
, "ejs": "0.4.x"
, "expresso": "0.9.x"
, "qs": "0.1.x"
, "should": "*"
{
"name": "express-resource",
"description": "Resourceful routing for express",
"version": "1.0.0",
"homepage": "https://github.com/visionmedia/express-resource",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
{
"name": "Daniel Gasienica",
"email": "daniel@gasienica.ch"
}
],
"dependencies": {
"lingo": ">= 0.0.4",
"methods": "0.0.1",
"debug": "*"
},
"devDependencies": {
"connect": "2.x",
"express": "3.x",
"ejs": "0.4.x",
"qs": "0.1.x",
"mocha": "*",
"should": "*",
"supertest": "0.1.2"
},
"keywords": [
"express",
"rest",
"resource"
],
"main": "index",
"engines": {
"node": "*"
}
, "keywords": ["express", "rest", "resource"]
, "main": "index"
, "engines": { "node": ">= 0.2.0" }
}
}
# Express Resource
express-resource provides resourceful routing to express.
express-resource provides resourceful routing to express. For Express 2.x
use a version __below__ 1.0, for Express 3.x use 1.x.

@@ -174,3 +175,3 @@ ## Installation

Copyright (c) 2010-2011 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2010-2012 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2011 Daniel Gasienica <daniel@gasienica.ch>

@@ -177,0 +178,0 @@

Sorry, the diff of this file is not supported yet

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