When working with ASP.Net Web API, it is important to return a consistent response for all the requests that are processed by your API regardless of success or failure.

This makes it a lot easier to consume the API, without requiring complex code on the client.

By using a custom wrapper for Web API responses, you can ensure that all of your responses have a consistent structure, and you can also include custom metadata.

This article presents a discussion on how we can decorate Web API responses with useful information.Let’s understand the problem we are trying to solve.
In essence, your standard Web API response will vary when executing different action methods, and we need a way to get around the inconsistency of these responses. When you are trying to retrieve data using HTTP GET, the response may contain data for one or more records. When you are executing a HTTP POST, the response may not even include a body, but only a header.

And when there is an error when executing the request, the API will return an object with the appropriate error message.To read this article in full or to leave a comment, please click here

Leave a Reply