ASP.NET Web API 2: Building a REST Service from Start to Finish
Download Full Version of the eBook "ASP.NET Web API 2: Building a REST Service from Start to Finish"
Download - ASP.NET Web API 2: Building a REST Service from Start to Finish by Jamie Kurtz - PDF
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 configuration 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 jаvascript application, or 99-cent mobile app, in a matter of days—and those applications needed a simple HTTP-only, JSON-compatible back end. The 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. Configuration is available (though almost completely unnecessary), and you can spin up a RESTful service in a matter of minutes.
The 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 first 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 first 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.
We have also made improvements in response to your feedback regarding the source code that accompanied the first book. Therefore, on GitHub you will find a git repository containing all of the code for the task-management service we will build together (https://github (dot) com/jamiekurtz/WebAPI2Book). The repository contains one branch per chapter, with multiple check-ins (or “commits”) per branch to help guide you step-by-step through the implementation. The repository also includes a branch containing the completed task-management service, with additional code to help reinforce the concepts that we cover in the book. Of course, feel free to use any of this code in your own projects.
I am very excited about this book. Both Brian and I are firm believers in the “Agile way,” which at its heart is all about feedback. So we carefully triaged each and every comment I received from the first book and did our best to make associated improvements. And I’m really excited about all the new features in the second version of ASP.NET Web API. So many capabilities have been added, but Microsoft has managed to maintain the framework’s simplicity and ease of use.
We hope you not only find this book useful in your daily developer lives, but also find it a pleasure to read. As always, please share any feedback you have. We not only love to hear it, but your feedback is key in making continuous improvements.