final-space-api icon indicating copy to clipboard operation
final-space-api copied to clipboard

API Response Restructure

Open sno2 opened this issue 3 years ago • 8 comments

Is your feature request related to a problem? Please describe. Currently, all character and episode endpoints just return the character/episode json or an array of the character/episodes that match the request.

Describe the solution you'd like I think that all correct responses should have one of the following formats:

{
  "status": 200,
  "data": {}
}

or

{
  "status": 200,
  "results": [],
}

Of course, the response status should match the correct status of the response. If we changed to doing this, though, then it would allow us to include errors in incorrect responses that doesn't look weird. For example, if I were getting data from a certain character, but I sent the request to /character/9999, we only get a 502 Bad Gateway message. We should, however, return the following data:

{
  "status": 404,
  "message": "The character you have requested was not found."
}

Edit: the message property could be swapped for error.

Using statuses instead of errors allows an easier debugging process, as the developer can access the message and status that the servers sent.

I will work on a PR if this is deemed as needed by the community.

sno2 avatar Oct 08 '20 12:10 sno2

@CodingCarter This is great, this will be really awesome and helpful.

I will guess I will include this in v2 but go ahead and work on this.

I will assign this to you.

Looking forward to this.

lelouchB avatar Oct 08 '20 13:10 lelouchB

Great, I have school right now, but I will have this done by tonight.

sno2 avatar Oct 08 '20 13:10 sno2

No problem You can take your time.

lelouchB avatar Oct 08 '20 13:10 lelouchB

Hey @sno2 Any update on this?

lelouchB avatar Nov 01 '20 07:11 lelouchB

@lelouchB If @sno2 is not doing it, then can I do this one?

P.S. I know I have said for the quote endpoint too but I would like to start from here and then head to that

Mayank0255 avatar Nov 17 '20 06:11 Mayank0255

@Mayank0255

This is an enhancement issue and its not a priority for me. If you want I can assign this to you and you can start working on it.

But I will most likely include this update in v2 of the API i.e. with GraphQL support.

lelouchB avatar Nov 17 '20 06:11 lelouchB

@lelouchB

Okay I think you are right we should leave that for now.

Mayank0255 avatar Nov 17 '20 06:11 Mayank0255

@Mayank0255 Sure 👍

lelouchB avatar Nov 17 '20 06:11 lelouchB