You are previewing ASP.NET Web API 2 Recipes: A Problem Solution Approach.
O'Reilly logo
ASP.NET Web API 2 Recipes: A Problem Solution Approach

Book Description

ASP.NET Web API Recipes provides you with the code to solve a full range of Web API problems and question marks that you might face when developing line-of-business applications. ASP.NET Web API Recipes gives you an in-depth explanation for each of these scenarios and shows you how to use Web API with a vast array of .NET application development tools and external libraries, to solve common business problems. Find out how you can build custom web services with ASP.NET Web API more efficiently than ever.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgements
  10. Introduction
  11. Chapter 1: Web API in ASP.NET
    1. 1-1. Add ASP.NET Web API to an MVC Application
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 1-2. Add ASP.NET Web API to a Web Forms Application
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 1-3. Accept an HTML Form
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 1-4. Link from MVC Controller to API Controller and Vice Versa
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 1-5. Use Scaffolding with ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 1-6. Add Model Validation
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 1-7. Use CSRF Protection
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 1-8. Add Support for Session State
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  12. Chapter 2: ASP.NET Web API Outside of IIS
    1. 2-1. Self-Host ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 2-2. Host ASP.NET Web API with OWIN
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 2-3. Host ASP.NET Web API in Azure Mobile Services
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 2-4. Quick Prototypes with scriptcs
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 2-5. Host ASP.NET Web API in Azure Worker Role
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 2-6. Use ASP.NET Web API with F#
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  13. Chapter 3: Routing
    1. 3-1. Define Centralized Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 3-2. Define Direct Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 3-3. Set Default Route Values
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 3-4. Set Optional Route Values
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 3-5. Set Route Constraints
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 3-6. Define Remote Procedure Call Style Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 3-7. Create Catch-all Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 3-8. Prevent Controller Methods from Inadvertently Becoming Web API Endpoints
      1. Problem
      2. Solution
      3. How It Works
      4. Solution
    9. 3-9. Configure Route-Specific Message Handlers
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    10. 3-10. Ignore Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    11. 3-11. Localize Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    12. 3-12. Generate a Link to the Route
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  14. Chapter 4: Content Negotiation and Media Types
    1. 4-1. Request a Specific Media Type from ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 4-2. Support Additional Media Types
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 4-3. Control Model Binding From URI and Body
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 4-4. ASP.NET MVC-style Parameter Bindingin ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 4-5. Customize XML and JSON Responses
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 4-6. Write Your Own MediaTypeFormatter
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 4-7. Run Content Negotiation Manually
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 4-8. Bypass Content Negotiation
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    9. 4-9. Control Media Types with MediaTypeMappings
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    10. 4-10. Serve Binary Data from ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    11. 4-11. Accept File Uploads
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    12. 4-12 Enable Bufferless Uploads
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    13. 4-13 Validate File Uploads
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  15. Chapter 5: Configuration and Customization
    1. 5-1. Throttle ASP.NET Web API Calls
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 5-2. Use Controllers from an External Assembly
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 5-3. Use Controller-Scoped Configuration
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 5-4. Validate Input with Action Filters
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 5-5. Override Filters
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 5-6. Add Caching to ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 5-7. Use an Existing Caching Library
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 5-8. Order Filter Execution with Custom Filters
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    9. 5-9. Order Filter Execution Without Custom Filters
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    10. 5-10. Customize Error Detail Policy
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    11. 5-11. Return HTML from ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    12. 5-12. Store Objects for the Duration of HTTP Request
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  16. Chapter 6: Embrace HTTP with ASP.NET Web API
    1. 6-1. Work Directly with HttpRequestMessage
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 6-2. Support Partial GET
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 6-3. Support the HEAD Verb
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 6-4. Support the PATCH Verb
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 6-5. Support Batching of HTTP Requests
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 6-6. Automatic HTTP 406/Not Acceptable Server Responses
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 6-7. Implement Versioning of a Web API with Centralized Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 6-8. Implement Versioning of a Web API with Attribute Routing
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    9. 6-9. Use Custom HTTP Content
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  17. Chapter 7: Exceptions, Troubleshooting, and Documenting
    1. 7-1. Handle Exceptions with Filters
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 7-2. Handle Exceptions Globally
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 7-3. Log Exceptions Globally
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 7-4. Add a Tracer
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 7-5. Use an External Tracer
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 7-6. Call the Tracer Manually
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 7-7. Write a Real-Time Tracer
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 7-8. Create a Documentation Page for ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    9. 7-9. Add Custom Samples to ASP.NET Web API Help Page
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    10. 7-10. Add Filters Information to ASP.NET Web API Help Page
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    11. 7-11. Support Data Annotations in ASP.NET Web API Help Page
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  18. Chapter 8: Cross Domain and Push Communication
    1. 8-1. Use JSONP in ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 8-2. Use CORS in ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 8-3. Create Custom CORS Policies
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 8-4. Support Streaming and Push from ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 8-5. Support Server-Sent Events in ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 8-6. Integrate ASP.NET SignalR into ASP.NET Web API controllers
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 8-7. Use WebSockets with ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  19. Chapter 9: Dependency Injection
    1. 9-1. Inject Dependencies into ASP.NET Web API Controllers
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 9-2. Add Support for the Most Popular DI Containers
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 9-3. Deal with Request Scope
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 9-4. DI with Other ASP.NET Web API Components
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 9-5. Write a Custom DI Adapter
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  20. Chapter 10: Securing an ASP.NET Web API Service
    1. 10-1. Use Correct Web API Components for Security-Related Tasks
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 10-2. Add HTTPS Support to ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 10-3. Use Basic Authentication
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 10-4. Integrate Windows Authentication
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 10-5. Use the Hawk Authentication Scheme
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 10-6. Use OAuth 2.0 with ASP.NET Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 10-7. Safely Access Current IPrincipal
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 10-8. Remove ASP.NET Web API Server Footprint
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  21. Chapter 11: Testing Web API Services
    1. 11-1. Unit Test ASP.NET Web API Controllers
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 11-2. Unit Test Message Handlers
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 11-3. Unit Test Action Filters
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 11-4. Unit Test Formatters
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    5. 11-5. Simplify Tests with IHttpActionResult
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    6. 11-6. Test Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    7. 11-7. Integration Testing
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    8. 11-8. Integration Testing with OWIN
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  22. Chapter 12: OData
    1. 12-1. Creating OData Services in Web API
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    2. 12-2. Manage OData Routes
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    3. 12-3. Enable OData Queries
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
    4. 12-4. Support OData Functions and Actions
      1. Problem
      2. Solution
      3. How It Works
      4. The Code
  23. Index