3.2.1 • Published 6 years ago

super-router v3.2.1

Weekly downloads
63
License
-
Repository
github
Last release
6 years ago

Super Router

Travis build status

API Docs

Code coverage Report

const SuperRouter = require('super-router');
const app      = new SuperRouter.App();
const router   = new SuperRouter.Router();

router.addRoute({
  path    : '/cases',
  methods : 'get',
  handler : (opts) => {
    const request  = opts.request;
    const response = opts.response;

    return Database.getCases().then((cases)=>{
      response.setBody(cases);
    });
  }
});

router.addRoute({
  path    : '/cases/:caseId',
  methods : 'get',
  handler : (opts) => {
    const request  = opts.request;
    const response = opts.response;

    return Database.getCaseById(request.routeParams.caseId).then((case)=>{
      response.setBody(case);
    });
  }
});

app.then({
  path : '/cases/externalId/:externalId(/*restOfRoute)',
  handler : (opts) => {
    const request  = opts.request;
    const response = opts.response;

    return Database.getCaseByExternalId(request.routeParams.externalId).then((case)=>{
      request.path = `/cases/${case.id}${request.routeParams.restOfRoute}`
    });
  }
});
app.then(router.match);
app.then(router.execute);
app.then((opts) => {
  const request  = opts.request;
  const response = opts.response;

  response.setBody(JSON.stringify(response.getBody()));
})
3.2.1

6 years ago

3.2.0

6 years ago

3.1.4

8 years ago

3.1.3

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago