Going on with our code. Let's see how we will design our response objects. Always return JSON with an object on that side. This is what is stated by the open web application security project. Always have that site primitive be an object for JSON strings. As you can see from the examples, there are some safe and less safe way to structure your response object.
If you want to know something more about it or if you have, if you want to know the reasons behind these statements statement, please visit the link that I leave here at the bottom of this slide as a source. As you can see, there are some security reasons but I like to have a solid data format for my response objects. So what we are going to do is to create two Different response objects, one for the success response or one for the error response. For the sexual response, we will have our success attributes that will be through our studies could represent the HTTP status code, an optional message that describes that has some meaningful, meaningful message for the user. And the payload will contain the real resource what we have requested, the URL response will have a success attribute set to false on HTTP status code message and a call to the uniquely identifies the error.
So as you can see, and there is a common pattern and we can organize it in a common response. object that we have the success to the scope and message property. So we are going to extend this response to create the success response in the error response. Then we will have two functions that will take care of the setup of the response object in order to send the result of the requested operation. These are particularly useful if you want to add later sub procedures will or behavior for example, if you want to add an email at the end of the error response