# REST

The router option allows any route and response to be defined using an Express router:

const myService = {
  router: (router) => {
    router.get('/some/route', (req, res) => {
      res.send({ foo: 'bar' });
    });
  }
}

The store is available as a second argument, making it possible to return the same values and perform the same mutations as a GraphQL resolver:

const myService = {
  router: (router, store) => {
    // get data from the store
    router.get('/books/:id', (req, res) => {
      const $book = store.get('Book', Number(req.params.id));
      res.send({
        id: store.get($book, 'id'),
        title: store.get($book, 'title'),
      });
    });

    // apply a mutation to the store
    router.put('/books/:id', (req, res) => {
      const $book = store.get('Book', Number(req.params.id));
      store.set($book, req.body);
      res.send({
        id: store.get($book, 'id'),
        title: store.get($book, 'title'),
      })
    })
  }
}