codecasts / spa-starter-kit

A highly opinionated starter kit for building Single Page Applications with Laravel and Vue.js
MIT License
913 stars 134 forks source link

API Response Format #109

Closed jaonoctus closed 7 years ago

jaonoctus commented 7 years ago

Would be nice if all of spa-starter-kit's REST API responses conform to the JSend Specification.

This means that every response will have a status and a data field in the JSON response. The status field will give either a success or fail. In the case of a success, the data will contain the requested data. In the case of a fail, the data will contain error messages.

For example, in the case of a bad request:

{
"status": "fail",
"data": {
"errors": [
{ "name": "title", "message": "cannot be this ridiculous" },
{ "name": "description", "message": "must be provided" }       
]
}
}

Here is an example of a successful request of a public profile:

{
"status": "success",
"data": {
"id": 1,
"email": "spa-starter-kit@codecasts.rocks"
}
}
vedovelli commented 7 years ago

@JaoNoctus Thanks for the suggestion! Very welcome.

@flyingluscas would you like to comment on this?

flyingluscas commented 7 years ago

@JaoNoctus Thanks for the suggestion, at this moment we have a similar structure, except we dont have a status field, I didn't think it was needed because we are using the http status codes to know if there was any errors or not, that way we always have to use the right status codes when returning a response, but what do you think @vedovelli ?

vedovelli commented 7 years ago

@JaoNoctus @flyingluscas If we have something in place, I'd suggest leave it as it is. Specially because a package was suggested to implement the idea. Thanks guy, I'm closing this issue.