Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route handling #4

Closed
zzarcon opened this issue Apr 8, 2016 · 5 comments
Closed

Route handling #4

zzarcon opened this issue Apr 8, 2016 · 5 comments
Assignees

Comments

@zzarcon
Copy link
Member

zzarcon commented Apr 8, 2016

The Router must use https://github.com/pillarjs/path-to-regexp to handle requests

Draft...

import {router} from 'kakapo';

router.get('/users', usersHandler);
router.post('/users/:user_id', createUser);

function usersHandler(request, db) {
  return {
    users: db.all('user');
  };
};

function createUser(request, db) {
  db.create('user', request.params.id);
};
@zzarcon zzarcon added the Router label Apr 8, 2016
@zzarcon zzarcon self-assigned this Apr 8, 2016
@rpunkfu
Copy link
Contributor

rpunkfu commented Apr 9, 2016

I think we should support queries! :) Also we probably should pass object as a second argument to filter db.find

import { router } from 'kakapo';

router.get('/users?size=42&page=7', usersHandler);
router.get('/users/:id', usersHandler);

const usersHandler = (request, database) => ({
    users: database.find('user', request.params, request.query.size);
});

@rpunkfu
Copy link
Contributor

rpunkfu commented Apr 9, 2016

As I think of that, we shouldn't have router & database being so tightly coupled... imo router shouldn't know anything about database:

import { Database, Router } from 'kakapo';

const database = new Database(/* bla bla bla */);
const router = new Router(/* bla bla bla */);

database.register('user', /* bla bla bla */);

router.get('/users?size=42&page=7', usersHandler);
router.get('/users/:id', usersHandler);

const usersHandler = request => ({
    users: database.find('user', {id: request.params.id}, {size: request.query.size});
});

@zzarcon
Copy link
Member Author

zzarcon commented Apr 9, 2016

request.params already implemented 💪 and I like the request.query i was not sure about which name to use for that one ^^

@zzarcon
Copy link
Member Author

zzarcon commented Apr 10, 2016

@oskarcieslik should we close this issue and create a new one with the point of decoupling the router and the db?

@rpunkfu
Copy link
Contributor

rpunkfu commented Apr 10, 2016

Yes, I will close this after tests for query implementation pass :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants