19 Creating RESTful web services

 

This chapter covers

  • Using ASP.NET Core to create RESTful web services
  • Creating web services with the minimal API
  • Creating web services with controllers
  • Using model binding data from web service requests
  • Managing the content produced by web services

Web services accept HTTP requests and generate responses that contain data. In this chapter, I explain how the features provided by the MVC Framework, which is an integral part of ASP.NET Core, can be used to build on the capabilities described in part 2 to create web services.

The nature of web services means that some of the examples in this chapter are tested using command-line tools provided by PowerShell, and it is important to enter the commands exactly as shown. Chapter 20 introduces more sophisticated tools for working with web services, but the command-line approach is better suited to following examples in a book chapter, even if they can feel a little awkward as you type them in. Table 19.1 puts RESTful web services in context.

19.1 Preparing for this chapter

19.2 Understanding RESTful web services

19.2.1 Understanding request URLs and methods

19.2.2 Understanding JSON

19.3 Creating a web service using the minimal API

19.4 Creating a web service using a controller

19.4.1 Enabling the MVC Framework

19.4.2 Creating a controller

19.5 Improving the web service

19.5.1 Using asynchronous actions

19.5.2 Preventing over-binding

19.5.3 Using action results

19.5.4 Validating data

19.5.5 Applying the API controller attribute

19.5.6 Omitting Null properties

19.5.7 Applying a rate limit

Summary