NIHIRA TECHIEES
WEB API - FULL COURSE
.NET CORE - VERSION 7.0
Introduction
* Web API stands for Application programming Interface
* We can develop Web API using different technologies
such as .NET & JAVA etc.
* .NET Core Web API is an extensible framework for
building HTTP based services that can be accessed in
different applications on different platforms such as
web, windows, mobile etc.
Advantage
* Open source
* Cross platform support
* Better testability
* Can deploy IIS Server & Cloud
API WORKFLOW
Topics
* System setup & Installation
* Create first .NET Core Web API
* Application folder structure
* Common Http Response
Topics
* Middleware & Dependency injection
* Entity Framework Core
* Auto Mapper
* Logging using serilog
Topics
* Enable CORS
* Rate Limiter
* Basic crud actions
* Authentication
Topics
* Authentication
1, Basic Authentication
2, JWT Authentication
3, Refresh Token
Topics
* Image Handling (upload & Download)
* Generate PDF & Excel
* Send email with attachment
* Minimal API
Topics
* Deployment in IIS Server
* Environmental Variable handling
* Real time application
Topics
* Real Time Application
1, Create API for User Authentication
2, Generate API for Real time POS Application
User Authentication
* User Registration
* User Login
* User role based menu access
* Assign role based permission
POS Application
* Customer API
* Product API
* Master API (Category , Currency, Tax, Term)
* POS Sales Screen API (Covers CRUD actions & Send
email with invoice attachment)
System setup
* Operating system (Windows , Linux & Max)
* Source editor (Visual studio 2022, VS Code , etc)
* Install .NET SDK & .NET Runtime
https://dotnet.microsoft.com/en-us/download/dotnet
/7.0
Common HTTP Response
Code Action Code Action
200 OK 404 Not Found
201 Created 406 Not Acceptable
202 Accepted 423 Locked
204 No Content 500 Internal Server Error
400 Bad Request 501 Not Implemented
401 Un Authorized 502 Bad Gateway
403 Forbidden 503 Service Unavailable
Middleware
* A middleware is nothing but a component (class) which
is executed on every request in ASP.NET Core application.
• Middleware components are executed in the order they
are added to the pipeline
* Middleware can be built-in as part of the .NET Core
framework, added via Nugget packages, or can be custom
middleware.
Dependency Injection
* Dependency injection is the inbuilt feature in .NET Core.
* It provides 3 ways to register DI to service
Transient
It creates an instance each time they are requested and are never shared. It is used mainly
for lightweight stateless services.
Singleton
This creates only single instances which are shared among all components that require it.
Scoped
It creates an instance once per scope which is created on every request to the application.
Entity Framework core
* Entity Framework is an object-relational mapper
(O/RM).
* The Entity Framework provides three approaches to
create an entity model
1, Database First
2, Code First
3, Model First
EF core - Scaffold
Scaffold-DbContext [-Connection] [-Provider] [-
OutputDir] [-Context] [-Schemas>] [-Tables>]
[-DataAnnotations] [-Force] [-Project] [-
StartupProject] [<CommonParameters>]
Auto Mapper
* AutoMapper is a simple library that helps us to
transform one object type into another.
* Convention-based object-to-object mapper that
requires very little configuration.
* Library Used Automapper
Logging - Serilog
* Define Log path in app setting file
* Install the below packages
* Serilog.AspNetCore
* Serilog.Sinks.File
* Complete the logger configuration
Enable CORS
* Cross-origin resource sharing (CORS) is a browser
security feature that restricts cross-origin HTTP
requests .
* If your REST API's resources receive non-simple
cross-origin HTTP requests, you need to enable CORS
support.
1, https://domain1.com
2, https://domain2.com
Rate Limiting
* Rate limiting is a strategy for limiting network traffic.
* Rate limiting can help us to stop kinds of malicious
bot activity.
* It can also reduce strain on web servers.
Authentication
* Authentication is the process of validating user
identity & Authorization is the process of providing
permission to access the resource
* Authentication is used to protect our applications data
from unauthorized access.
Basic Authentication
* Basic authentication sends user names and passwords
over the Internet as text that is Base64 encoded, and
the target server is not authenticated.
* This form of authentication can expose user names
and passwords. If someone can intercept the
transmission, the user name and password
information can easily be decoded.
JWT Authentication
* JSON Web Tokens (JWT) are an open standard, which
is defined in JSON Web Token (JWT) Specification
RFC 7519.
* They securely represent claims between two parties.
Refresh Token
* A refresh token is a special token that is used to obtain
additional access tokens.
* This allows you to have short-lived access tokens
without having to collect credentials every time one
expires.
Image Handling
Upload
* Upload single image & store in server path
* Upload multiple images & store in server path
* Upload multiple images & store in database
Retrieve (GET Image)
* Get image from server path & database
Remove
* Remove from server path & database
Download Images
* Download from server path & database
Export Excel
• Create excel using closedXML
• Save Excel In Local Path
Minimal API
* Minimal APIs are architected to create HTTP APIs with
minimal dependencies.
* They are ideal for micro services and apps that want
to include only the minimum files, features, and
dependencies in ASP.NET Core.
* It’s introduced in .NET 6.0
Hosting in IIS Server
* Publish the app from visual studio
* Create new site in IIS and enable the configuration
NIHIRA TECHIEES
THANKS FOR WATCHING