Skip to main content

Posts

Showing posts with the label Web API

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

AutoMapper In Asp.Net Core Applications

AutoMapper: Automapper is an object-to-object mapper. Object to object mapping works by transforming an input object of one type into an output object of a different type. Manually mapping one object property value to another object property value leads to more lines of code, so all this dirty work can be avoided by using the Automapper. As long as all properties names are the same for 2 different objects that need to map, almost zero configuration is needed to map them.  When To Use AutoMapper?: In any kind of architecture, it is always advised to not expose the 'Entity'(Table classes) directly. So we will create replica classes for 'Entity' we called them as 'DTO'(Data Transfer Object) or 'VM'(View Models). So this is the real-time best case to use Automapper for mapping 'Entity'(Table classes) data to DTO or VM's. Create A Sample Dotnet5 Web API Project: In this demo, we are going to understand the different mapping techniques that are

A Demo On .Net5 Web API Pagination Using Dapper ORM

In this article, we are going to implement a sample demo on pagination in .Net5 Web API application using Dapper ORM for database communication. Create A Sample Table: To accomplish our demo let's create a sample table. CREATE TABLE [dbo].[Todo]( [Id] [int] IDENTITY(1,1) NOT NULL, [ItemName] [varchar](max) NULL, [IsCompleted] [bit] NOT NULL CONSTRAINT Pk_Todo PRIMARY KEY (Id) ) Create A .Net5 Web API Application: Let's create a .Net5 Web API application to implement our pagination. Specify the project name and solution name Select target framework a .Net5 Create Table Model and Pagination Response Model: Now we need to create to models like 'Todo'(Table Class) and 'PagingResponseModel'(Class that  used as API response model which contains all pagination properties). So let's add a new folder like 'Models' and our 2 classes inside of it. Models/Todo.cs: namespace Dot5.API.Dapper.Pagging.Models { public class Todo { public

.NET5 Web API CRUD Operation Using Entity Framework Core

In this article, we are going to understand about the .Net5 Web API CRUD operations using the entity framework core. Web API: Web API is a framework for building HTTP services that can be accessed from any client including browser and mobile devices. In simple terminology API(Application Programming Interface) means an interface module that contains programming functions that can be requested via HTTP calls to serve the data to 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 kind of apps or clients can consume it. Authentication and Authorization are easy to implement. The ideal platform to build REST full services. Create A .Net5 Web API Application: Let's begin our journey by creating a sample .Net5 Web API

Hot Chocolate GraphQL Custom Authentication Series Using Pure Code First Technique - Part1 - User Registration

About The Series: Using Pure Code First Technique In Hot Chocolate GraphQL, Custom Authentication Series: Part1 User Registration Resolver Part2 Generating JWT Access Token For User Authentication. Part3 Validating JWT Access Token And Different Authorization Techniques Part4 Generating Refresh Token. So this our Part-1 of the series where we are going to create a sample in GraphQL for user registration. SQL Tables: Create 2 tables like 'User' and 'UserRoles'. User Table: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName] [varchar](192) NULL, [LastName] [varchar](192) NULL, [EmailAddress] [varchar](192) NOT NULL, [Password] [varchar](640) NOT NULL, [RefreshToken] [varchar](640) NULL, [RefershTokenExpiration] [datetime] NULL, CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ( [UserId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY

Part-1 Hot Chocolate GraphQL JWT(JSON Web Token) Authentication - Generating User Login Access Token

In this article, we are going to implement a JWT authentication sample for the Hot Chocolate GraphQL endpoint. It's purely optional to implement JWT authentication in the GarphQL approach. Because .Net supports endpoint configuration for both normal .Net endpoint and GraphQL endpoint. While implementing GraphQL in your application and if you want to develop an authentication endpoint in the .Net approach there is no issue. But if you want to develop all endpoint in GraphQL including authentication that is also fine. So in this article, our goal is to create JWT authentication as a GraphQL endpoint. Create A .Net5 Web API Application: To understand the concept let's start our journey by creating a sample .Net5 Web API application. Recommended IDE for development are like Visual Studio 2019(Version 16.8.* for .Net5) or  Visual Studio Code . Install Hot Chocolate Library: Package Manager Command: Install-Package HotChocolate.AspNetCore -Version 11.0.2 .Net CLI Command: dotn