GetInfra WebApi Abstractions introduction
I would like to share a GetInfra.WebApi.Abstractions library I'm using in my recent projects. The bits can be found on Github or Nuget package
As havily working on Web API developement I've extracted several accpects in order not to repeat them in each project. In my case, having standard responses among dozens of microservices significally speed up a front-end developement. Maybe can be found useful for your projects as well.
The library includes abstractions for the following:
- Validation - refers to request validation
- Responses - several generic classes that can be used as response for api calls.
Validation
Validation is vital part of Web API development, and I as a developer would like to have a flexability to inject
custom validators by just implementing ValidatorBase<T>
.
Responses
Front-end developers always complian about the responses, especially when it comes to POST
, PUT
and DELETE
methods, To make it universal I came to following base response class:
{
"errors": [],
"validationErrors": [],
"isValid": true,
"succeeded": true
}
isValid - indicates if there are validation errors.
succeeded - indicates if there are runtime errors. by runtime I mean some try...catch
handled exeptions.
errors - array of run time exceptions
validationErrors - array of validation exceptions
Id or newId - depending on implementation, the id
property associated with the record.
There are several variations for the response:
GenericValResponse<T>
- to returns struct with associated IdGenericRefResponse<T>
- to returns class as associated Id
Another aspect the libarary is dealing with is list responses, which requires pagination and aggregation.
PagedResponse<T>
- paginated responsePagedResponseWithAggs<T>
- paginated response with aggregations
In next posts I will talk about how to create a custom validator, how to use custom regular expressions for your validators and how to form detailed response.
🚀 Turbocharge Your Infrastructure with Our Terraform Template Kits! 🚀
🌟 Slash deployment time and costs! Discover the ultimate solution for efficient, cost-effective cloud infrastructure. Perfect for DevOps enthusiasts looking for a reliable, scalable setup. Click here to revolutionize your workflow!
Learn More about Starter Terraform Kits for AKS,EKS and GKE
No comments are allowed for this post