Week#8(WebAPI)
Week#8(WebAPI)
Yin Hua Li
Centennial College
Week#8
1
¡ Web API offers a simple communication
technology based on Representational State
Transfer (REST)
2
3
4
5
6
7
¡ Add data model
8
¡ Install NuGet Package
9
¡ Register the database context
10
11
12
Object
ControllerBase
Controller
ControllerBase:
a base class for a
MVC controller
without view support
13
14
¡ The OpenAPI specification(here) is a language-
agnostic specification for machine-readable
interface files for describing, producing,
consuming and visualizing RESTful API
15
¡ RESTful API metadata includes 5 parts
§ Resource description
▪ Resource refers to the information returned by an API
§ Endpoints and methods
▪ The endpoints indicate how you access the resource, and the
method used with the endpoint indicates the allowed
interactions (i.e., GET, POST, PUT or DELETE) with the
resource
§ Parameters
§ Request example
§ Response example
16
¡ Web API routing matches the URI of a HTTP request to a
particular action (method) in an API controller.
¡ There are two ways of routing
§ Convention-based routing
21
22
23
24
¡ https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-
6.0&tabs=visual-studio
¡ https://learn.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/routing-
in-aspnet-web-api
25