Contents

About the Author

About the Technical Reviewer

imagePart 1: Getting Ready

imageChapter 1: Getting Readys

What Do You Need to Know?

What Does Expert Mean?

What Is the Structure of This Book?

Part 1: Getting Ready

Part 2: Results and Parameters

Part 3: Dispatching Requests

Are There Lots of Examples?

Where Can You Get the Example Code?

How Do You Set Up a Development Environment?

Getting Visual Studio

Getting Google Chrome

Summary

imageChapter 2: Your First Web API Application

Preparing the Example Project

Creating the Visual Studio Project

Adding and Updating NuGet Packages

Setting the Port and Start URL

Creating the MVC Application

Creating the Model

Creating the MVC Controller

Creating the Views

Using the MVC Application

Creating the Web Service

Creating the Web API Controller

Testing the Web API Controller

Implementing the Single-Page Client

Setting Up JavaScript IntelliSense

Defining the Client-Side Data Model and Controller

Registering the JavaScript File

Appling Data Bindings

Testing the Single-Page Client

Measuring the Single-Page Implementation

Summary

imageChapter 3: Essential Techniques

Preparing the Example Project

Adding and Updating NuGet Packages

Creating the Web API Controller

Creating the MVC Framework Controller

Setting the Port and Start URL

Testing the Web Service

Understanding Asynchronous Methods

Understanding the Problem Asynchronous Methods Solve

Implementing an Asynchronous Interface

Creating a Self-Contained Asynchronous Method Body

Returning a Task from a Synchronous Method Body

Making Ajax Requests with jQuery

Making an Ajax Request

Understanding the $.ajax Method

Using Knockout

Applying the Bindings

Summary

imageChapter 4: Understanding HTTP Web Services

Understanding ASP.NET Web API

Understanding Single-Page Applications

Understanding Native Applications

Understanding Shared-Model Applications

Understanding Service Applications

Understanding Simple Web Services

Understanding RESTful Web Services

Embracing HTTP

Adding Data Discovery

Summary

imageChapter 5: SportsStore: Preparation

Preparing the Example Project

Adding and Updating NuGet Packages

Creating a Prep Controller

Creating a Razor Layout

Creating the OWIN Startup Class

Setting the TCP Port

Creating the Product and Order Models

Defining the Model Classes

Creating the Repository Classes

Testing the Repository

Checking the Database Schema

Configuring ASP.NET Identity

Defining the User and Role Classes

Creating the Database Context Classes

Creating the Manager Classes

Adding the Configuration Statements

Testing ASP.NET Identity

Removing the Application Cookie

Summary

imageChapter 6: SportsStore: A RESTful Application

Creating a RESTful Web Service

Testing the Products Web Service

Putting the Web Service in Context

Working with Regular C# Objects

Using the RESTful Action Method Convention

Configuring Serialization

Adding Basic Data Validation

Securing the Product Web Service

Restricting Access to Action Method

Authenticating Requests

Adding Model Validation

Applying Validation Attributes

Validating the Model

Adding Simple Dependency Injection

Recapping the Problem

Creating the Dependency Resolver

Using the Dependency Resolver in the Controller Class

Creating a Non-RESTful Web Service

Preparing the Routing Configuration

Preparing the Model Objects

Preventing Formatting Loops

Defining the Web API Controller

Completing the Product Controller

Summary

imageChapter 7: SportsStore: Creating the Clients

Preparing the Example Project

Setting Up JavaScript IntelliSense

Updating the Layout

Implementing the Common Code

Defining the Ajax Layer

Defining the Model

Defining the Authentication Controller

Defining the Products Controller

Defining the Orders Controller

Creating the Customer Client

Creating the Customer Model

Creating the Customer Controller

Creating the Views

Creating the Administration Client

Creating the Admin Model

Creating the Admin Controller

Creating the Views

Testing the Admin Client

Summary

imageChapter 8: SportsStore: Deployment

Preparing the SportsStore Application

Preventing the Product Database from Resetting

Adding Database Connection Strings

Preparing Azure

Creating the Databases

Creating the Web Site

Downloading the Publish Profile

Deploying the Application

Configuring the Databases

Publishing the Application

Summary

imagePart 2: Results and Parameters

imageChapter 9: The Anatomy of ASP.NET Web API

Understanding the Web API Namespaces and Types

Understanding the Web API Context Objects

Getting Information About the Request

Getting Information About the Controller

Getting Information About Everything Else

Understanding the Web API Components

Application Configuration

Controllers, Actions, and Results

Services

Dispatchers and Handlers

Summary

imageChapter 10: Creating and Configuring a Web API Application

Preparing the Example Project

Creating the Model and Repository

Creating an HTTP Web Service

Creating the Browser Client

Testing the Example Application

Configuring a Web API Application

Configuring Web API Through the ASP.NET Platform

Understanding the Configuration Object

Configuring Web API Dependency Injection

Preparing for Dependency Injection

Understanding the Web API Dependency Interfaces

Installing the Dependency Injection Container

Implementing the Dependency Interfaces

Configuring Web API

Configuring Dependency Injection for Web API and MVC

Declaring the Dependency

Installing the Dependency Injection Packages

Adding MVC Support to the Resolver

Configuring the MVC Framework

Summary

imageChapter 11: Action Method Results

Preparing the Example Project

Understanding Action Method Results

Returning No Result

Consuming a No Result Action Method

Returning an Action Result

Understanding the IHttpActionResult Interface

Using the ApiController Action Result Methods

Returning Other Status Codes

Creating a Custom Action Result

Returning Model Data

Understanding the Default Behavior

Understanding the Content Negotiation Process

Implementing a Custom Content Negotiator

Bypassing Content Negotiation

Returning Negotiable Action Results

Creating Negotiable Action Results

Summary

imageChapter 12: Creating Media Type Formatters

Preparing the Example Project

Creating a Media Type Formatter

Implementing a Basic Media Type Formatter

Refining the Custom Formatter

Supporting Content Encodings

Setting the HTTP Response Headers

Participating in the Negotiation Process

Creating a Media Type Mapping

Using the Mapping Extension Methods

Creating Per-Request Media Type Formatters

Creating the Formatter Instance

Testing the Per-Request Formatter

Summary

imageChapter 13: Using the Built-in Media Formatters

Preparing the Example Project

Working with the Built-in Media Type Formatters

Listing the Built-in Media Type Formatters

Dealing with Type Matching During Negotiation

Working with the JSON Media Type Formatter

Configuring the JSON Media Type Formatter

Configuring Json.Net

Using the XML Media Type Formatter

Configuring the XML Media Type Formatter

Getting the Xml Media Type Formatter Working

Summary

imageChapter 14: Understanding Parameter and Model Binding

Preparing the Example Project

Creating the Controller

Creating the Client

Adding a New Route

Testing the Example Application

Understanding the Default Binding Behavior

Understanding Parameter Binding

Understanding Model Binding

Performing Binding Customizations

Binding Complex Types from the Request URL

Binding Simple Types from the Request Body

Defining a Binding Rule

Manually Obtaining Request Values

Handling POST Requests

Summary

imageChapter 15: Binding Simple Data Types

Preparing the Example Project

Preparing the Common Code

Working with Value Providers and Value Provider Factories

Understanding Value Providers and Value Provider Factories

Creating a Custom Value Provider and Factory

Applying a Custom Value Provider and Factory

Understanding How Web API Looks for Values

Applying a Value Provider Factory with an Attribute

Extending the Default Behavior

Creating a Parameter Binding Rule

Summary

imageChapter 16: Binding Complex Data Types Part I

Preparing the Example Project

Using the Built-in Model Binders

Binding Objects

Broadening the Source of Binding Values

Binding Collections and Arrays

Binding Key-Value Pairs

Working with Custom Model Binders

Preparing the Application

Understanding Model Binders

Creating a Custom Model Binder

Applying a Custom Model Binder

Using Type Converters

Understanding Type Converters

Creating a Type Converter

Applying a Type Converter

Summary

imageChapter 17: Binding Complex Data Types Part II

Preparing the Example Project

Testing the Application

Creating a Custom Media Type Formatter

Preparing the Client

Creating the Media Type Formatter

Registering and Testing the Media Type Formatter

Using the Built-in Media Type Formatters

Handling URL-Encoded Data

Handling JSON Requests

Handling XML Requests

Customizing the Model Binding Process

Changing the Behavior of the Default Action Value Binder

Creating a Custom Action Value Binder

Summary

imageChapter 18: Model Validation

Preparing the Example Project

Testing the Changes

Understanding Common Data Problems

Understanding Under-Posting

Understanding Over-Posting

Understanding Bad Data

Using Web API Model Validation

Understanding Model State

Testing the Model State

Removing the Debug Output Code

Using the Binding Control Attributes

Performing Validation with Validation Attributes

Using the Built-in Validation Attributes

Creating a Self-validating Model Class

Performing Validation in a Media Type Formatter

Creating a Validating Media Type Formatter

Registering and Using the Custom Media Type Formatter

Summary

imagePart 3: Dispatching Requests

imageChapter 19: Dispatching Requests

Preparing the Example Project

Creating the Model Class

Creating the Web API Web Service

Creating the MVC Controller and View

Testing the Example Application

Understanding Request Dispatching

Understanding the HttpServer Class

Understanding the HttpRoutingDispatcher Class

Understanding the HttpControllerDispatcher Class

Customizing the Dispatch Process

Creating Custom Message Handlers

Customizing Other Dispatch Components

Summary

imageChapter 20: URL Routing: Part I

Preparing the Example Project

Testing the Application Changes

Understanding URL Routing

Understanding the Routing Classes and Interfaces

Working with Convention-Based Routing

Using Route Templates

Routing to the New Controller

Controlling Route Matching

Using Routing Data Default Values

Using Routing Constraints

Summary

imageChapter 21: URL Routing: Part II

Preparing the Example Project

Understanding Direct Routing

Creating a Direct Route

Creating a Controller-wide Direct Route

Customizing URL Routing

Using a Route-Specific Message Handler

Applying Custom Constraints to Direct Routes

Summary

imageChapter 22: Controllers and Actions

Preparing the Example Project

Understanding Controllers

Creating a Controller

Using Built-in Services and Features

Understanding the ApiController Dispatch Process

Preparing the Example Controller

Understanding the Action Selection Process

Understanding the RESTful/Non-RESTful Routing Problem

Understanding Filters

Understanding the Action Method Execution Process

Customizing the Controller Dispatch Process

Creating a Custom IHttpActionInvoker Implementation

Creating a Custom IHttpActionSelector Implementation

Creating a Controller-Specific Configuration

Summary

imageChapter 23: Filters Part I

Preparing the Example Project

Understanding Filters

Working with Action Filters

Creating an Action Filter by Implementing IActionFilter

Using the Convenience Action Filter Base Class

Creating a Short-Circuiting Action Filter

Understanding the Filter Pipeline

Displaying the Filter Pipeline

Understanding Filter Scope

Working with Authentication Filters

Preparing for Authentication

Understanding Authentication Filters

Creating an Authentication Filter

Viewing the Filter Pipeline

Summary

imageChapter 24: Filters Part II

Preparing the Example Project

Reviewing Filters in the Dispatch Process

Working with Authorization Filters

Understanding Authorization Filters

Creating an Authorization Filter

Appling the Authorization Filter

Removing the Authentication Filter

Using the Built-in Authorization Filter Attributes

Reworking the Authentication Filter

Working with Exception Filters

Understanding the Default Behavior

Understanding Exception Filters

Creating an Exception Filter

Deriving the Filter from the ExceptionFilterAttribute Class

Working with Override Filters

Overriding Built-in Filter Types

Redefining Filter Policies

Summary

imageChapter 25: Error Handling

Preparing the Example Project

Dealing with Errors

Relying on the Default Behavior

Using an Implementation of the IHttpActionResult Interface

Using the HttpError Class

Using an Error Response and an HttpError Object

Adding Extra Information to the HttpError Object

Including Model State Errors in the HTTP Response

Controlling Error Detail

Displaying HttpError Information in the Client

Responding to Errors Globally

Handling Exceptions

Logging Exceptions

Summary

imageChapter 26: Using OWIN

Understanding OWIN

Creating a Self-hosted Web API Application

Creating the Project

Installing the Packages

Creating the Model and Repository

Defining the Configuration Classes

Creating the Web API Controller

Testing the Self-hosted Web API Application

Summary

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.189.251