halacious icon indicating copy to clipboard operation
halacious copied to clipboard

Wrap collection endpoints

Open clarkie opened this issue 9 years ago • 2 comments

Hi, I'm trying to add halacious to an existing REST api and can't find how to do so for collection end points.

For example the following returns an array of pieces:

{ 
    method: 'GET', 
    path: '/volumes/{id}/pieces', 
    config: {
      tags: ['api'],
      handler: function (request, reply) {
        var query = request.db.piece.findAll({
          where : { volumeId: request.params.id }
        });
        return reply(query);
      },
      validate: {
        params: {
          id: Joi.number().required()
        }
      }
    }
  }

Is this possible already or would this be a new feature?

clarkie avatar Oct 05 '15 09:10 clarkie

Hi!

You can’t really halify a top level array. We wrap all of our collection routes to return collection entities that include metadata about the collection (count, index, total count), links to first, previous, next, and last, and an embedded array of the actual items. Take a look at the paging.js halacious example in the examples folder.

On Oct 5, 2015, at 5:03 AM, Clarkie [email protected] wrote:

Hi, I'm trying to add halacious to an existing REST api and can't find how to do so for collection end points.

For example the following returns an array of pieces:

{ method: 'GET', path: '/volumes/{id}/pieces', config: { tags: ['api'], handler: function (request, reply) { var query = request.db.piece.findAll({ where : { volumeId: request.params.id } }); return reply(query); }, validate: { params: { id: Joi.number().required() } } } } Is this possible already or would this be a new feature?

— Reply to this email directly or view it on GitHub https://github.com/bleupen/halacious/issues/73.

bleupen avatar Oct 05 '15 12:10 bleupen

Hi!

You can’t really halify a top level array. We wrap all of our collection routes to return collection entities that include metadata about the collection (count, index, total count), links to first, previous, next, and last, and an embedded array of the actual items. Take a look at the paging.js halacious example in the examples folder.

On Oct 5, 2015, at 5:03 AM, Clarkie <[email protected] mailto:[email protected]> wrote:

Hi, I'm trying to add halacious to an existing REST api and can't find how to do so for collection end points.

For example the following returns an array of pieces:

{ method: 'GET', path: '/volumes/{id}/pieces', config: { tags: ['api'], handler: function (request, reply) { var query = request.db.piece.findAll({ where : { volumeId: request.params.id } }); return reply(query); }, validate: { params: { id: Joi.number().required() } } } } Is this possible already or would this be a new feature?

— Reply to this email directly or view it on GitHub https://github.com/bleupen/halacious/issues/73.

bleupen avatar Oct 05 '15 12:10 bleupen