Skip to main content

Posts

Showing posts with the label Asp.net core 3.0

GraphQL API Integration In Asp.Net Core Application

Introduction: GraphQL is a query language for your API and a server-side runtime for executing queries by using a type system you define for your data. GraphQL can be integrated into any framework like ASP.NET, Java, NestJs, etc and it isn't tied to any specific database or storage engine and is instead backed by your existing code and data. How GraphQL API Different From Rest API: GraphQL exposes a single end-point or route for the entire application, regardless of its responses or actions. HTTP-POST is the only Http verb recommended by the GraphQL. The client applications (consumers of API) can give instructions to GraphQL API about what type of properties to be returned in the response. Building Blocks Of GraphQL API: The main building blocks of GraphQL API is Schemas and Types.  A 'Schema' in GrpahQL API describes the functionality available to the clients connect to API. Schema mostly consists of GraphQL Object Types, Queries, Mutations, etc. T

ASP.NET Core Web API Versioning

Introduction: An iteration and evolutionary changes of an ASP.NET Core Web API is handled by Versioning. Versioning of an API gives confidence to the clients which consumes API for a long time. Any changes or development of an API will be accessible using the new version and it won't cause issues to the clients consuming the old version of API. When To Use Versioning: Any API response changes. Developing an API by implementing testing levels like 'Alpha', 'Beta', and 'RC' versions before releasing Production. Deprecating an API which means API going to be removed or upgraded by a version within a short period. Versioning Types: Query String Versioning Url Path Versioning Media Type Versioning API Version Nuget: To Configure versioning to AspNet Core Web API Microsoft provided a library(Microsoft.AspNetCore.Mvc.Versioning). So to use the versioning library please install NuGet below.              Install-Package Microsoft.A

Dotnet Core MVC Cookie Login Sample Role-based Authorization (Part 2)

Introduction: Authorization means an authenticated user having permission to access specific protected resources. In general, Authorization can be called special permissions. For example in an application, an admin user has all permission to modify the application, a non-admin user might have permission likes read-only content in the application. In the  first article , we have discussed the Cookie-Based login mechanism. This will be a continuation article, here we discuss Authorization. Note: Before reading this article, read  Dotnet Core Cookie Login Sample (Part 1) . Pages Controller: Now add a new controller name as 'PagesController.cs' and to this controller add 3-action methods to show 3 pages in the application. PagesController.cs: namespace CookieAuth.Web.Controllers { [Route("pages")] public class PagesController : Controller { [Route("admin")] [HttpGet] public IActionResult Admin() {

Dotnet Core MVC Cookie Login Sample From Scratch(Part 1)

Introduction: In general ASP.NET Core applications(MVC, RazorPages, WebAPI, Blazor Server Side) use login libraries like ASP.NET Core Identity , IdentityServer4 , OAuth 2.0 , etc. But ASP.NET Core can simply implement login with using Cookie-Based Authentication  without any login libraries. ASP.NET Core Identity  is a membership program that helps to create a login functionality. Its rich library with all default login functionalities, creating users, adding roles, password encryption, and support to social logins like Google, Facebook, Outlook, Twitter, etc. IdentityServer4 Or OAuth 2.0  is the latest login technology. It also gives all login functionalities and support to social logins as well additionally Single Sign-On and   Token-Based user login. Cookie-Based Authentication  is a default login mechanism provided by ASP.NET Core applications. But user creation, adding roles need to be done manually which is not hard to do. In this approach, we don't