xxi
Introduction
With the introduction of services technology over a decade ago, Microsoft made it relatively easy to build and
support web services with the .NET Framework. Starting with XML Web Services, and then adding the broadly
capable Windows Communication Foundation (WCF) several years later, Microsoft gave .NET developers many
options for building SOAP-based services. With some basic conguration changes, you could support a wide array
of communication protocols, authentication schemes, message formats, and WS-* standards with WCF. But as
the world of connected devices evolved, the need arose within the community for a simple HTTP-only services
framework—without all of the capabilities (and complexity) of WCF. Developers realized that most of their newer
services did not require federated authentication or message encryption, nor did they require transactions or Web
Services Description Language (WSDL)–based discovery. And the services really only needed to communicate over
HTTP, not named pipes or MSMQ.
In short, the demand for mobile-to-service communication and browser-based, single-page applications started
increasing exponentially. It was no longer just large enterprise services talking SOAP/RPC to each other. Now a
developer needed to be able to whip up a JavaScript application, or 99-cent mobile app, in a matter of days—and
those applications needed a simple HTTP-only, JSON-compatible back end. e Internet needs of these applications
looked more and more like Roy Fielding’s vision of connected systems (i.e., REST).
And so Microsoft responded by creating the ASP.NET Web API, a super-simple yet very powerful framework
for building HTTP-only, JSON-by-default web services without all the fuss of WCF. Model binding works out of the
box, and returning Plain Old CLR Objects is drop-dead easy. Conguration is available (though almost completely
unnecessary), and you can spin up a RESTful service in a matter of minutes.
e previous edition of this book, ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish,
spent a couple chapters describing REST and then dove into building a sample service with the rst version of
ASP.NET Web API. In a little over a hundred pages, you were guided through the process of implementing a working
service. But based on reader feedback, I discovered that a better job needed to be done in two major areas: fewer
opinions about patterns and best practices and various open source libraries, and more details on the ASP.NET Web
API itself. So when the second version of the ASP.NET Web API was released, Brian Wortman and I decided it was time
to release a version 2 of the book. Brian wanted to help me correct some glaring “bugs,” and also incorporate some
great new features found in ASP.NET Web API 2. And so this book was born.
In this second edition, we will cover all major features and capabilities of the ASP.NET Web API (version 2).
We also show you how to support API versioning, input validation, non-resource APIs, legacy/SOAP clients (this
is super cool!), partial updates with PATCH, adding hypermedia links to responses, and securing your service with
OAuth-compatible JSON Web Tokens. Improving upon the book’s rst edition, we continue to evolve the message
and techniques around REST principles, controller activation, dependency injection, database connection and
transaction management, and error handling. While we continue to leverage certain open source NuGet packages,
we have eliminated the chatter and opinions around those choices. We also spend more time on the code—lots of
code. Unit tests and all. And in the end, we build a simple KnockoutJS-based Single Page Application (SPA) that
demonstrates both JSON Web Token authentication and use of our new service.
www.it-ebooks.info
- 1
- 2
- 3
前往页