SHARE:

ASP.NET Core 6: Minimal APIs, two reasons why I can’t do without it so far

Introduction

A few days ago I introduced you to the minimal APIs, in this blog post: https://anthonygiretti.com/2021/08/12/asp-net-core-6-working-with-minimal-apis/
They are an evolution of the Route to Code concept which was already an interesting concept in ASP.NET Core. I described how it works here: https://anthonygiretti.com/2020/06/29/nano-services-with-asp-net-core-or-how-to-build-a-light-api/
Today I will explain to you the two reasons why I can not do without it

Quick and easy exposure of protobuf files via REST

None of my gRPC projects fail to use the exposure of protobufs files with minimal APIs anymore, it’s so easy to use! The following service is used to list protobuf files and their version, download a protobuf file or display the content of a protobuf file in a browser:

Then, by dependency injection I’m able to expose them easily on a minimal endpoint:

What I love above all is the efficiency of the static Results class. With that class I can expose json data easily with the Ok() method, expose file content with the Text() method or provide file download with the File() method.

Example with File() method, I’m able to import protobuf via the Connected Services mnu in Visual Studio 2022:

Quick Entity Framework Core dbContext testing

Who doesn’t like Entity Framework Core? I adore. and you know I love it too? to be able to quickly test if my dbContext I have configured it correctly, suddenly I want to quickly test if with a DbSet I can make requests to the database, you never know I may have done something wrong? Well the minimal APIs, still through dependency injection, allow me to inject my Dbcontext and test a LINQ request and see if everything works correctly:

Example with Postman:

Practical isn’t it ? 😉

Written by

anthonygiretti

Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.
%d bloggers like this: