Alex's Coding Blog
  • Home
  • About
  • Projects
  • Contact me

Blog

GetInfra WebApi Abstractions introduction

  • November 20, 2019 January 09, 2020
  • by Alexander

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 Id
  • GenericRefResponse<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 response
  • PagedResponseWithAggs<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.

.NET Core

Debugging microservices is always tricky and time consuming specially without proper code level logging in place.

Meet Konso. It's developed as a solution for this challenge and can help with saving development effort for your team up to 30%. 🎯🎉

The key functions are:

🔥 Centralized logging for your microservices
🔥 Tracing with metrics and value tracking events
🔥 Ad-Hoc events exploration
🔥 Saving your queries
🔥 Create alerts and get notified


You can start collecting you project's logs in 5 minutes. 🕐💪

To Learn more about logging tool, book a free demo.
To get started for free, Create your free account now

Alexander Lvovich

Solution Architect and Software Developer.

Share on:

No comments are allowed for this post

Recent Posts

  • Easily track and troubleshoot errors in your .NET 7 web app using Konso's logging feature
  • How to disable object model validation .NET 7
  • Keep Your Passwords Safe: 5 Tips for Protecting Yourself After the Latest LastPass Data Breach
  • How to ping from .net application container
  • Freelancing myths you should consider before dive in
  • How to set up a honey token for dotnet project with Konso

Categories

  • Azure
  • Architecture
  • .NET Core
  • Certification
  • DevOps
  • How-to
  • Azure Functions
  • Serverless
  • Cosmos DB
  • Security
  • Thoughts
© Copyright 2023, Alexander Lvovich. Theme by Colorlib