13 Middleware, HTTP routing, and HTTP responses
This chapter covers
- Routing HTTP requests to controllers and endpoints
- Declaring HTTP routes with
HttpAttribute
method attributes - Injecting dependencies with middleware
- Using the
IActionResult
interface to return HTTP responses
We are almost at the end of our journey. In chapters gone by, we implemented the database access layer, the repository layer, and the service layer. Our service is almost implemented, but not yet usable by FlyTomorrow (our client). To interact with our service, we need to provide controllers that accept HTTP requests and kick off the necessary processing.
In section 13.1, we discuss the controller’s place within our Repository/Service architecture. Following that, in section 13.2, we determine which controllers we need to implement. In the following sections, we start to implement the FlightController
(section 13.3) and explore how to route HTTP requests to our endpoints (section 13.4).
Figure 13.1 In the previous chapters we implemented the database access, repository, and service layers. In this chapter, we start to implement all controllers needed for our service.

After this chapter, we are only one more chapter away from having a fully implemented service that adheres to the API specification given to us by FlyTomorrow. In the next chapter, we finish up by wrapping up our controllers and diving into acceptance testing with Swagger so we can prove we did our work correctly.