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

Server duties #14

Closed
zzarcon opened this issue Apr 9, 2016 · 0 comments
Closed

Server duties #14

zzarcon opened this issue Apr 9, 2016 · 0 comments

Comments

@zzarcon
Copy link
Member

zzarcon commented Apr 9, 2016

The Server component is in charge of connect all the other Kakapo pieces. A real example could be something like:

import {Router, DB, Server} from 'Kakapo';

const db = new DB();
db.register('user', (faker) => {
  return {
    firstName: faker.name.firstName,
    lastName: 'Zarco',
    avatar: faker.internet.avatar,
    age: 24
  };
});

const router = new Router({host: 'custom'});
router.get('/users/', (request, db) => {
  return db.all('user');
});

router.get('/users/:user_id', (request, db) => {
  return db.find('user', request.params.id);
});

router.post('/users/', (request, db) => {
  const createdUser = db.create('user', request.body.user.id);

  return createdUser;
});


const server = new Server({requestDelay: 500});

server.use(db);
server.use(router);
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