Practical ASP.NET Web API

Book description

Practical ASP.NET Web API provides you with a hands-on and code-focused demonstration of the ASP.NET Web API in action. From the very beginning, you'll be writing working code in order to see best practices and concepts in action. As the book progresses, the concepts and code will become more sophisticated. Beginning with an overview of the web service model in general and Web API in particular, you'll progress quickly to a detailed exploration of the request binding and response formatting that lie at the heart of Web API. You'll investigate various scenarios and see how they can be manipulated to achieve the results you need.

Later in the book more sophisticated themes will be introduced that will set your applications apart from the crowd. You'll learn how you can validate the request messages on arrival, how you can create loosely coupled controllers, extend the pipeline processing to compartmentalize your code for security and unit testing before being put onto a live hosting server.

What you'll learn

  • What ASP.NET Web API is and how it can be used effectively

  • Ways to optimize your code for readability and performance

  • What controller dependencies are and why they matter

  • How to maintain robust security across your projects

  • Reliable best-practices for using Web API in a professional context

  • Who this book is for

    The book is ideal for any .NET developer who wants to learn how the ASP.NET Web API framework works in a realistic setting. A good working knowledge of C# and the .NET framework and a familiarity with Visual Studio are the only pre-requisites to benefit from this book

    Table of contents

    1. Title Page
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Author
    6. About the Technical Reviewer
    7. Introduction
    8. CHAPTER 1: Building a Basic Web API
      1. 1.1 Choosing ASP.NET Web API or WCF
      2. 1.2 Exposing an In-Memory List over HTTP
      3. 1.3 Choosing Configuration over Convention
      4. 1.4 Playing by the Rules of HTTP
      5. Summary
    9. CHAPTER 2: Debugging and Tracing
      1. 2.1 Using Fiddler for Web Debugging
      2. 2.2 Capturing Console App Traffic through Fiddler
      3. 2.3 Capturing HTTPS Traffic in Fiddler
      4. 2.4 Composing and Submitting Requests in Fiddler
      5. 2.5 Using F12 Developer Tools in Internet Explorer
      6. 2.6 Using Developer Tools in Chrome
      7. 2.7 Enabling ASP.NET Web API Tracing
      8. 2.8 Creating a Custom Trace Writer
      9. 2.9 Tracing Entry and Exit
      10. 2.10 Tracing from Your Code
      11. 2.11 Tracing Request and Response Messages
      12. Summary
    10. CHAPTER 3: Media-Type Formatting CLR Objects
      1. 3.1 Listing the Out-of-Box Media Formatters
      2. 3.2 Understanding Conneg
      3. 3.3 Requesting a Content Type through the Query String
      4. 3.4 Requesting a Content Type through the Header
      5. 3.5 Implementing a Custom Media Type Mapping
      6. 3.6 Overriding Conneg and Returning JSON
      7. 3.7 Piggybacking on Conneg
      8. 3.8 Creating a Custom Media Formatter
      9. 3.9 Extending an Out-of-Box Media Formatter
      10. 3.10 Controlling Which Members Are Serialized
      11. 3.11 Controlling How Members Are Serialized
      12. 3.12 Returning Only a Subset of Members
      13. Summary
    11. CHAPTER 4: Customizing Response
      1. 4.1 Negotiating Character Encoding
      2. 4.2 Supporting DBCS Character Encoding (Shift JIS)
      3. 4.3 Negotiating Content Encoding (Compression)
      4. 4.4 Negotiating Language
      5. Summary
    12. CHAPTER 5: Binding an HTTP Request into CLR Objects
      1. 5.1 Reading the Raw HTTP Request
      2. 5.2 Reading the HTTP Request into a CLR Type
      3. 5.3 Binding the HTTP Request to Simple Types
      4. 5.4 Binding the HTTP Request to Complex Types
      5. 5.5 Binding the HTTP Request to a Collection
      6. 5.6 Binding the Form Data
      7. 5.7 Binding dd/MM/yyyy Dates
      8. 5.8 Using TypeConverter
      9. 5.9 Creating a Custom Value Provider
      10. 5.10 Creating a Custom Model Binder
      11. 5.11 Creating a Custom Parameter Binder
      12. 5.12 Creating a Custom Media Formatter
      13. Summary
    13. CHAPTER 6: Validating Requests
      1. 6.1 Validation Using Data Annotations
      2. 6.2 Handling Validation Errors
      3. 6.3 Extending an Out-of-the-Box Validation Attribute
      4. 6.4 Creating Your Own Validation Attribute
      5. 6.5 Implementing the IValidatableObject Interface
      6. Summary
    14. CHAPTER 7: Managing Controller Dependencies
      1. 7.1 Taking Dependency on the Entity Framework
      2. 7.2 Inverting Entity Framework Dependencies
      3. 7.3 Using the Repository Pattern
      4. 7.4 Using the Generic Repository Pattern
      5. 7.5 Mapping a Domain to Data Transfer Object (DTO)
      6. 7.6 Injecting Dependencies Using StructureMap
      7. 7.7 Unit-Testing the Controller
      8. Summary
    15. CHAPTER 8: Extending the Pipeline
      1. 8.1 Creating a Message Handler
      2. 8.2 Creating an Exception Filter
      3. 8.3 Creating an Action Filter to Handle Concurrency
      4. 8.4 Creating a Controller Selector for Versioning
      5. Summary
    16. CHAPTER 9: Hosting ASP.NET Web API
      1. 9.1 Web Hosting ASP.NET Web API
      2. 9.2 Self-Hosting ASP.NET Web API
      3. 9.3 In-Memory Hosting ASP.NET Web API
      4. Summary
    17. CHAPTER 10: Securing ASP.NET Web API
      1. 10.1 Implementing Direct Authentication
      2. 10.2 Implementing Brokered Authentication
      3. 10.3 Authorizing Requests
      4. Summary
    18. CHAPTER 11: Consuming ASP.NET Web API
      1. 11.1 Calling a Web API from a Console Application
      2. 11.2 Calling a Web API from a WPF Application
      3. 11.3 Calling a Web API from JavaScript
      4. Summary
    19. CHAPTER 12: Building a Performant Web API
      1. 12.1 Creating Asynchronous Action Methods
      2. 12.2 Pushing Real-time Updates to the Client
      3. 12.3 Implementing Simple Web Caching
      4. Summary
    20. Index

    Product information

    • Title: Practical ASP.NET Web API
    • Author(s):
    • Release date: August 2013
    • Publisher(s): Apress
    • ISBN: 9781430261759