Answer the question
In order to leave comments, you need to log in
How are requests other than CRUD implemented in the JSON API?
CRUD is clear, but what about atypical requests. for example, the SignUp action, which should return the status, messages, and redirect address in case of successful registration, or fields containing errors if the form was not validated on the server. Well, the essence itself in this case is not a model. Someone can kick on the implementation of such methods, or an example of what should eventually be sent to the client
Answer the question
In order to leave comments, you need to log in
According to personal experience, the most correct thing in such a situation is to return an object explicitly containing all the fields you listed + a field with the final status of the operation (in order to attach the front logic to it).
If some fields are not applicable for some status, we simply return null there.
{
'status' : '1',
'message' : 'Success!',
'url' : 'https://mysite.com',
'errors' : null
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question