Skip to content

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

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

Open
telip007 opened this issue Sep 3, 2018 · 1 comment
Open

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

telip007 opened this issue Sep 3, 2018 · 1 comment
Milestone

Comments

@telip007
Copy link

telip007 commented Sep 3, 2018

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
Copy link
Member

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.

@anthonycastelli anthonycastelli added this to the 2.0.0 milestone Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants