Chapter 9. Creating a Web API for mobile and client applications using MVC

 

This chapter covers

  • Creating a Web API controller to return JSON to clients
  • Using attribute routing to customize your URLs
  • Generating a response using content negotiation
  • Enabling XML formatting

In the previous five chapters, you’ve worked through each layer of a traditional ASP.NET Core MVC application, using Razor views to render HTML to the browser. In this chapter, you’ll see a slightly different take on an MVC application. We’ll explore Web APIs, which serve as the backend for client-side SPAs and mobile apps.

You can apply much of what you’ve learned to Web APIs; they use the same MVC design pattern, and the concepts of routing, model binding, and validation all carry through. The differentiation from traditional web applications is entirely in the view part of MVC. Instead of returning HTML, they return data as JSON or XML, which client applications use to control their behavior or update the UI.

In this chapter, you’ll learn how to define controllers and actions and see how similar they are to the controllers you already know. You’ll learn how to create an API model to return data and HTTP status codes in response to a request, in a way that client apps can understand.

9.1. What is a Web API and when should you use one?

 
 
 

9.2. Creating your first Web API Controller

 
 

9.3. Applying the MVC design pattern to a Web API

 
 
 

9.4. Attribute routing: taking fine-grained control of your URLs

 
 
 

9.5. Enabling additional input formatters: binding to XML data

 
 

9.6. Generating a response from a model

 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest