Skip to main content

Posts

Showing posts with the label ASP.NET Core Web API

Part-3 Create A Microservice For The Orders Endpoint[.NET6 Microservice Series]

In this article, we will create our second microservice application that contains the orders endpoint. The microservice application consists of simple or single module logic endpoints. So here I'm going to create 2 endpoints like HTTP GET, HTTP POST for the 'Orders' to accomplish our demo. Part-2 Create A Microservice For The Products Endpoint[.NET6 Microservice Series] Create A .NET6 Web API Application: Let's create our second microservice application with .NET6 Web API application. Let's name our microservice project 'SalesBusiness.Api'. To create .NET6 application recommended IDE's are 'Visual Studio 2022', 'Visual Studio Code'. In this demo, I'm using .NET CLI and Visual Studio Code editor. CLI command dotnet new webapi -o Your_Project_Name Install NuGet Packages: Install EntityFramework Core NuGet. .NET CLI command dotnet add package Microsoft.EntityFrameworkCore --version 6.0.3 Package Manager command Install-Packa

.NET6 Web API CRUD Operation With MongoDB

In this article, we are going to implement .NET6 Web API CRUD operation using MongoDB as database. MongoDB: MongoDB is a source-available cross-platform document-oriented database. It is also called a NoSQL database or Non-Relational database. In MongoDB 'Collection' is equivalent to the Table in SQL database. In MongoDB data is stored as 'Document' that is equivalent to a table record in an SQL database. The 'Document' contains JSON data which will be stored in BSON(Binary JSON) format. Create A .NET6 Web API Application: Let's create a .Net6 Web API sample application 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 dotnet new webapi -o Your_Project_Name MongoDB Docker Image: In this demo, I will consume the MongoDB that's run as a Docker container.

.NET6 Web API CRUD Operation With Entity Framework Core

In this article, we are going to do a small demo on AspNetCore 6 Web API CRUD operations. What Is Web API: Web API is a framework for building HTTP services that can be accessed from any client like browser, mobile devices, desktop apps. In simple terminology API(Application Programming Interface) means an interface module that contains a programming function that can be requested via HTTP calls to save or fetch the data for their respective clients. Some of the key characteristics of API: Supports HTTP verbs like 'GET', 'POST', 'PUT', 'DELETE', etc. Supports default responses like 'XML' and 'JSON'. Also can define custom responses. Supports self-hosting or individual hosting, so that all different kinds of apps can consume it. Authentication and Authorization are easy to implement. The ideal platform to build REST full services. Create A .NET6 Web API Application: Let's create a .Net6 Web API sample application to accomplish our

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

.NET Application Controller Actions Now Support Asynchronous Streaming Response[.NET6 Feature]

In this article, we will know about .NET6 feature that is MVC/API controller actions now supports the asynchronous streaming response. Async Stream: A data stream is often retrieved or generates elements asynchronously is 'Async Stream'. Now from .NET6 we can output the async stream of response from the controller's actions. An action method that contains return type 'IAsyncEnumerable' no longer buffers the response content in application memory before it sends to the clients. So not buffering help to reduce the application memory usage when returning large dataset result that can be asynchronously enumerated. Sample Action Method That Returns 'IAyncEnumerable<T>' Results: Let's write a sample code that can return the asynchronous stream of data. [Route("Test")] [HttpGet] public async IAsyncEnumerable<int> GetNumbers() { for (int i = 1; i < 100; i++) { await Task.Delay(10); Console.WriteLine(i); yield return i;

A Demo On Request Logging Using MediatR IPipelineBehavior In Asp.Net Core Application

Click here  for step by step implementation of the CQRS MediatR design pattern. In this article, we are going to do request logging into an Asp.Net application Core application build on the CQRS MediatR design pattern. The application request logging helps to track the time taken per request. The MediatR provides a pipeline interface that is 'IPipelineBehavior' that helps to implement our logging logic. IPipelineBehavior: The 'IPipelineBehavior' exactly works like Asp.Net Core middleware, but its starting execution and ending execution happens within the 'IMediator'. So the 'IMediator.send()' is usually used to invoke the 'Query' or 'Command' handlers. So if we implement 'IPipelineBehavior' then begin logic inside of its start executes then invokes 'Query' or 'Command' handlers, later again go through 'IPipelineBehavior' and executes the end logic. Create A .Net5 Web API Sample Application: In this