Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ampersand-express-router

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-express-router - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

package.json
{
"name": "ampersand-express-router",
"description": "Serverside backbone router inspired by backbone router and ampersand-router.",
"version": "0.0.1",
"version": "0.0.2",
"author": {

@@ -6,0 +6,0 @@ "name": "Lally Elias",

@@ -5,5 +5,3 @@ # ampersand-express-router

<!-- starthide -->
Part of the [Ampersand.js toolkit](http://ampersandjs.com) for building severside applications.
<!-- endhide -->

@@ -16,68 +14,65 @@ ## install

<!-- starthide -->
## example
```javascript
var Router = require('ampersand-express-router');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var Router = require('ampersand-express-router');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
extended: false
}));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
extended: false
}));
// parse application/json
app.use(bodyParser.json());
// parse application/json
app.use(bodyParser.json());
var UserRouter = Router.extend({
var UserRouter = Router.extend({
// ------- ROUTES DEFINITIONS ---------
routes: {
'users|post': 'create',
'users|delete': 'destroy',
'users|put': 'edit',
'users|get': 'all',
'users/:id|get': 'show'
},
// ------- ROUTES DEFINITIONS ---------
routes: {
'users|post': 'create',
'users|delete': 'destroy',
'users|put': 'edit',
'users|get': 'all',
'users/:id|get': 'show'
},
// ------- ROUTE HANDLERS ---------
create: function(request, response) {
response.json({
name: 'create'
});
},
destroy: function(request, response) {
response.json({
name: 'destroy'
});
},
edit: function(request, response) {
response.json({
name: 'edit'
});
},
all: function(request, response) {
response.json({
name: 'all'
});
},
show: function(request, response) {
response.json({
name: request.param('id')
});
}
// ------- ROUTE HANDLERS ---------
create: function(request, response) {
response.json({
name: 'create'
});
},
destroy: function(request, response) {
response.json({
name: 'destroy'
});
},
edit: function(request, response) {
response.json({
name: 'edit'
});
},
all: function(request, response) {
response.json({
name: 'all'
});
},
show: function(request, response) {
response.json({
name: request.param('id')
});
}
...
});
...
});
var UsersRoute = new UserRouter({
app: app
});
var UsersRoute = new UserRouter({
app: app
});
app.listen(3000);
app.listen(3000);
```
<!-- endhide -->

@@ -88,3 +83,3 @@ ## API Reference

Get started by creating a custom router class. Define actions that are triggered when certain URL are matched, and provide a [routes](#ampersand-express-router-routes) hash that pairs routes to actions. Note that you'll want to avoid using a leading slash in your route definitions:
Get started by creating a custom router class. Define actions that are triggered when certain URL are matched, and provide a routes hash that pairs routes to actions. Note that you'll want to avoid using a leading slash in your route definitions:

@@ -96,3 +91,3 @@ ```javascript

"users|get": "all", // /users
"users/:id": "show", // /users/11
"users/:id|get": "show", // /users/11
},

@@ -120,3 +115,2 @@

<!-- starthide -->
## credits

@@ -128,3 +122,2 @@

MIT
<!-- endhide -->
MIT
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