

WEBSITE APP WRAPPER CODE
If you want to skip the actual code implementation, there are two separate Nuget packages that you can integrate directly to your project: VMD.RESTApiResponseWrapper Nuget Packages We will take a look at how we are going to implement a custom wrappers that handles all the features listed above for both ASP.NET Core and standard Web APIs. By using a custom wrapper for your ASP.NET Core and Web API responses, you can ensure that all of your responses have a consistent structure, and all exceptions will be handled. This makes it a lot easier to consume the API, without requiring complex code on the client. When working with either ASP.NET Core or standard Web API, it is important to handle exceptions and return consistent responses for all the requests that are processed by your API regardless of success or failure.

Your GET end-point may return a string, a List, an IEnumerable, a custom class or an object. Your POST, PUT and DELETE end-points may return a data or not at all. Each of this action may return different types depending on how your method/action is designed. To make it clearer, if you are taking a RESTful approach to your API then you will be utilising HTTP verbs such as GET, POST, PUT and DELETE. Why we need to implement a custom wrapper and why it’s a good thing.ĪSP.NET Core and the standard ASP.NET Web API allow us to create APIs in just a snap however they do not provide a consistent response for successful requests and errors out of the box. Why?īefore we move down further, let’s talk about the “Why” thing first.
WEBSITE APP WRAPPER HOW TO
This article will talk about how to implement a custom wrapper for your ASP.NET Core and Web API applications for managing exceptions, providing meaningful and consistent responses to consumers. As you may know, creating Web API’s is an easy task, but designing a good API isn’t as easy as you may think especially if you are working with a lot of projects or microservices that exposes some public API end-points. Building RESTFul API’s has been very popular nowadays and most projects that we build today heavily rely on APIs/Services to communicate with data.
