I am pretty new to Web Api, how can I return customized JSON response?
I want to achieve something like this:
In the case where there was an error from the server side, the return will be:
{"success":false,"error_code": XXX, "error_msg":"ERROR_MESSAGE"}
Then, if everything is working fine the return will be one of two possible results, the following is presented in the case where the service will return just one element (find by id).
{"success":true,"MODEL_NAME":{"attr_name1":"attr_value1", ...}}
Finally, the following element will present the object that will be returned in the case where the request is for getting a list of elements
{"success":true,"PLURAL_MODEL_NAME":[{"attr_name1":"attr_value1", ...}, {...}, ...]}