express-routes-mapper
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "express-routes-mapper", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "a small mapper for express routes", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
# express-routes-mapper | ||
## a simple package to map your routes for your expressjs application | ||
> a simple package to map your routes for your expressjs application | ||
## Getting started | ||
- [Start from ground](#start-from-ground) | ||
- [supported methods](#supported-methods) | ||
- [dynamic routes](#dynamic-routes) | ||
## Start from ground | ||
This is a example for a simple rest API. | ||
@@ -48,3 +54,3 @@ | ||
create (req,res) { | ||
create (req, res) { | ||
@@ -60,3 +66,3 @@ res.send('created a User with es6'); | ||
'create': function(req,res){ | ||
'create': function (req, res) { | ||
@@ -113,3 +119,3 @@ res.send('created a User with es5'); | ||
const server = http.Server(app); | ||
const port = 4444; | ||
const port = 3338; | ||
@@ -132,3 +138,3 @@ app.use('/', mapRoutes(routes)); | ||
var server = http.Server(app); | ||
var port = 4444; | ||
var port = 3339; | ||
@@ -140,3 +146,58 @@ app.use('/', mapRoutes(routes)); | ||
console.log('Gladly listening on http://127.0.0.1:' + port); | ||
}) | ||
}); | ||
``` | ||
## Supported methods | ||
* GET | ||
* POST | ||
* PUT | ||
* DELETE | ||
```js | ||
{ | ||
'GET /someroute' : 'SomeController.somefunction', | ||
'POST /someroute' : 'SomeController.somefunction', | ||
'PUT /someroute' : 'SomeController.somefunction', | ||
'DELETE /someroute' : 'SomeController.somefunction' | ||
} | ||
``` | ||
## Dynamic routes | ||
Simply use a colon ':' for defining dynamic routes. | ||
```js | ||
{ | ||
'GET /someroute/:id' : 'SomeController.somefunction' | ||
} | ||
``` | ||
If you make a get request to `http://localhost/someroute/1` the 1 (:id) is now in the 'SomeController accessible. | ||
```js | ||
//es6 | ||
export default class SomeController { | ||
somefunction (req, res) { | ||
let id = req.params.id; | ||
} | ||
} | ||
//es5 | ||
module.exports = { | ||
'somefunction': function (req, res) { | ||
var id = req.params.id | ||
} | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8030
198