This bullet list... This slide is with animations Model-View-ControllerArchitectural pattern Loose coupling, separation of concerns: testability, reuse Not the full application architec
Trang 2This bullet list
Trang 3ASP.NET Core MVC
ASP.NET MVC
(client-facing web applications)
ASP.NET Web API
(http services)
Middleware for Building an API
Trang 4This slide is
with
animations
Model-View-ControllerArchitectural pattern
Loose coupling, separation of concerns: testability, reuse
Not the full application architecture!
Clarifying the MVC Pattern
Trang 5Model
Trang 6Clarifying the MVC Pattern
Consumer of the API
Resource representation
(often JSON)
Model
Trang 9This slide is
with
animations
Matches request URI to controller method
Convention-based and attribute-based routing
Learning About Routing
Trang 10app.UseMvc(config => {
config.MapRoute(
name: "Default",template: "{controller}/{action}/{id?}",defaults: new { controller="Home", action="Index" }); });
Convention-based Routing
Conventions need to be configured
Not advised for API’s
Trang 12HTTP Method Attribute Level Sample URI
GET HttpGet Action /api/cities
/api/cities/1 POST HttpPost Action /api/cities
PUT HttpPut Action /api/cities/1
PATCH HttpPatch Action /api/cities/1 DELETE HttpDelete Action /api/cities/1
- Route Controller
-Routing
Trang 15- What is responsible for a failed request
The Importance of Status Codes
Trang 16500 – Internal Server Error
Trang 20Media type is passed via the Accept header
Trang 21Output formatter
Deals with output
Media type: accept header
Trang 23This bullet list
with
animations
Model-View-Controller
- Model: application data logic
- View: display data
- Controller: interaction between View and Model
- More reuse, better testabilityRouting: maps URI to controller method
Summary
Trang 24This bullet list
with
animations
Content negotiation: selecting the best representation for a given response
- Output formatters (accept header)
- Input formatters (content-type header)
Summary