vapor-community / pagination

Simple Vapor 3 Pagination
MIT License
64 stars 15 forks source link

Is there a way to customize the response format? #14

Open telip007 opened 6 years ago

telip007 commented 6 years ago

Can I customize the response to include the URLs for the next pages and also have a meta section? Similar to this:

{
  "meta": {
    "total-pages": 13
  },
  "data": [
    {
      "type": "articles",
      "id": "3",
      "attributes": {
        "title": "JSON API paints my bikeshed!",
        "body": "The shortest article. Ever.",
        "created": "2015-05-22T14:56:29.000Z",
        "updated": "2015-05-22T14:56:28.000Z"
      }
    }
  ],
  "links": {
    "self": "http://example.com/articles?page[number]=3&page[size]=1",
    "first": "http://example.com/articles?page[number]=1&page[size]=1",
    "prev": "http://example.com/articles?page[number]=2&page[size]=1",
    "next": "http://example.com/articles?page[number]=4&page[size]=1",
    "last": "http://example.com/articles?page[number]=13&page[size]=1"
  }
}
anthonycastelli commented 6 years ago

Unfortunately there isn't a way. I'm not sure what the best way to get this type of response would be since there really isn't a solid way to get the base URL in Vapor. Once I finish up some work on my projects I plan on coming back to this and reworking a few things. If you have any solutions or idea, definitely feel free to submit a pull request.

Ideally I'd like to to have two different responses for this.

  1. The current implementation
  2. This version

It would be nice to allow anyone to build out their own custom implementation but that can be something for the future.