Skip to main content

Posts

Showing posts with the label Minimal Web API

Minimal API 'Result.Stream()' Return Type[.NET6]

In this article, we will know about a Minimal API return type that is 'Result.Stream()' Result.Stream(): The 'Result.Steam()' can be used to deliver the stream of data as a response from the Minimal API endpoint. For example on consuming a third-party API from our minimal API endpoint, a common approach is to read the response from the third-party API and then deserialize the response and finally return the response using 'Result.Ok()'. But using 'Result.Stream()' return type we can directly return the stream of third-party API response without deserializing. Create A .NET6 Minimal API Project: Let's create a .Net6 Minimal API sample project to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net6 application. For this demo, I'm using the 'Visual Studio Code'(using the .NET CLI command) editor. CLI command For Minimal API Project dotnet new webapi -minimal -o Your_

Different HttpClient Techniques To Consume API Calls In Minimal API[.NET6]

In this article, we are going to implement different HttpClient techniques to consume API calls in minimal API. The different HttpClient techniques that we are going to explore are like: Register HttpClient Object Explicitly In DI(Dependency Injection Service) Named Client Type Client HttpRequestMessage Object Create A .NET6 Minimal API Project: Let's create a .Net6 Minimal API sample project to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net6 application. For this demo, I'm using the 'Visual Studio Code'(using the .NET CLI command) editor. CLI command For Minimal API Project dotnet new webapi -minimal -o Your_Project_Name Create A Third Party API Response Model: Here I'm going to use a free third-party rest API that is "https://jsonplaceholder.typicode.com/posts". So to receive the response let's create a response model like 'Post.cs'. Program.cs:(Add Post.cs c

Implement IResult For Custom Response In Minimal API[.NET 6]

In this article, we will understand the implementation of IResult for custom response in minimal API[.NET6]. IResult Type: In minimal API to return a custom response, we have to implement the 'Microsoft.AspNetCore.Http.IResult'. class CusomtResult : IResult { public Task ExecuteAsync(HttpContext httpContext) { throw new NotImplementedException(); } } The 'ExecuteAsync' method gets automatically invoked, the only parameter it will have is the 'HttpContext' where we can use to append our custom response type. Create A .NET6 Minimal API: Let's create a .Net6 Minimal API sample project to accomplish our sample. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any .NET6 application. For this demo, I'm using the 'Visual Studio Code'(using .NET CLI commands) editor. CLI command For Minimal API Project dotnet new webapi -minimal -o Your_Project_Name Implementing Custom Response W

A CRUD Operation Demo On Asp.NetCore Minimal Web API[Asp.NetCore 6.0 Feature]

Minimal API: The concept of creating an HTTP API with minimal dependencies is Minimal APIs. It was introduced in Asp.Net 6, and they are ideal for microservices that can be finished with minimum files and features. In Minimal API there won't be any controller or action methods. In Minimal API, the logical execution function will be registered along with the route registration. On comparing Minimal API with the normal Web API, that Minimal API doesn't support(for Asp.Net Core 6  these won't support but in the upcoming versions, these may be available) the following features like: Minimal API doesn't support built-in validation. Minimal API doesn't support filters. Minimal API doesn't support versioning. Minimal API doesn't support OData. Create A .Net6 Minimal API Project: Let's create a .Net6 Minimal API sample project to accomplish our CRUD sample. We can use either Visual Studio 2022 or Visual Studio Code (using .NET CLI commands) to create any .Ne