+ All Categories
Home > Technology > dotNet Miami - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

dotNet Miami - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Date post: 12-Dec-2014
Category:
Upload: dotnet-miami
View: 727 times
Download: 3 times
Share this document with a friend
Description:
dotNet Miami - April 19th, 2012: Presented by Cecil Phillip:: Interested in learning about building HTTP services? Want to know how you can easily leverage HTTP in your .NET projects? Come see how the ASP.NET Web API allows you to work with HTTP in interesting ways to create rich services that are easily accessible from various clients. Along the way, we’ll also address some topics such as Content Negotiation, Validation, Media Types, Action Filters and more.
Popular Tags:
26
Building HTTP based Web Services with ASP.NET Web API Cecil L. Phillip @cecilphillip
Transcript
Page 1: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Building HTTP based Web Services with ASP.NET Web API

Cecil L. Phillip

@cecilphillip

Page 2: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Overview

Short Review of HTTP

ASP.NET Web Stack

Web API Pipeline

Web API Extensibility Points

HTTP Tools

DEMOS!!

Page 3: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Why HTTP Services ?

Light Weight

Support for Multiple Formats

HTTP Caching

Accessible from a variety devices

Page 4: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

HTTP Messages

Request and Response Messages consist of An Initial Start Line Zero or More Message Headers An Optional Message Body

RFC 2616 - HTTP 1.1 Spec http://www.w3.org/Protocols/rfc2616/rfc2616.html

Page 5: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

HTTP Request Methods Identifies the Action against the Resource

The HTTP Spec defines eight Method Types

A few of these Methods include: POST – Create a new Resource GET – Retrieve the Resource PUT – Create or Update a Resource DELETE – Delete the Resource

Most Web Browsers only support GET and POST

Page 6: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

HTTP Headers Provide valuable meta data for the message

Some Standard Headers include: Accept – Accepted formats by the Client Content-Type – Format associated with the request

body Host – Server domain name User-Agent – Client software identifier

Additional fields may be added by the Server or Application

Page 7: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

HTTP Headers cont.. Common Uses Include

Setting Cookies Defining Caching Passing Authentication credentials

Non standard header fields are prefixed with “X-”

IANA Header Field Name Registry http://goo.gl/lcUlU

Page 8: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

HTTP Status Codes Identify the type of request success and

failures

Some codes you might see: 2xx – Successful Response

201 - Created 3xx – Redirect Response

301 – Moved Permanently 4xx – Client Error Response

401 – Unauthorized 5xx – Service Error Response

503 – Service Unavailable

Page 9: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Web API Lineage

Page 10: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

ASP.NET STACK

ASP.NET Core

Sites

MVC Web Forms

Web Pages

Singe Page Apps

Services

Web API SignalR

Page 11: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Web API and MVC Build Web Applications with MVC and Web Services

with Web API

ASP.NET Web API is not dependent on ASP.NET MVC

Shared Concepts between the Frameworks Controllers Filters Model Binding Model Validation Routing Dependency Resolver

Page 12: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Web API Framework Features

Strongly Typed API for working with HTTP Messages

Content Negotiation Pluggable Messaging Pipeline Code Based Configuration IoC Support OData Query Composition Flexible Hosting Options

Page 13: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Where Do I Get It?

NuGet

Web Platform Installer

Microsoft Download Center

Page 14: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Web API Pipeline

Http Client

Message

Handler

Message

Handler

Http Client Handle

r

Http Server

Message

Handler

Message

Handler

Http Dispatcher

API Client Side

API Server Side

Page 15: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Web API Dispatcher

Invoke Action

Model Binding

Action Selection

Controller Selection

Request

Exception Filters

Formatting

Response

Authorization Filters

Action Filters

Page 16: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Media Types Used to Identify Resources Format Types

Used in Various Networking Protocols e.g. HTTP, RTP, SMTP

Vendor Specific Formats begin with vnd.

Web API supports XML, JSON, and Form-Urlencoded data out of the box

IANA Media Type Listinghttp://www.iana.org/assignments/media-types

Page 17: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Content Negotiation

Service Clients tell the Server about Desired Formats

Servers returns Resources in Supported Format

ASP.NET Web API supports XML and JSON out of the box

Additional Formats can easily plugged in

Page 18: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Filters Borrowed concept from ASP.NET MVC

Replaced Operation Handlers from the Web API Previews

Can be applied on various levels Per Controller, Per Action, or Global

Filter Types Action Filters – executes before and/or after an

operation Authorization Filters – executes before model

binding Exception Filters – catch unhandled operation

exceptions

Page 19: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Message Handlers Provides a Pipeline for processing HTTP

Messages

Allows for Inspection and Manipulation of HTTP Messages in transit

Common Uses: Logging / Tracing Adding and Removing HTTP Headers Message Filtering

Page 20: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Securing Your Service

Enable HTTPS / SSL on the Servers

Generate API Keys

Implement Authentication Tokens

Use Key Encryption

Page 21: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Hosting Options

ASP.NET Web Hosting Uses the HttpControllerHandler async handler

Self Hosting Translates messages using a WCF channel stack

In-Memory Hosting Good for testing

Page 22: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

HttpClient Configurable class for sending

HttpRequestMessages

Originally in the Rest Starter Kit [2009]

Only Asynchronous Public Methods

Included in .NET 4.5

Available in the System.Net.Http NuGet Package

Page 23: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

HTTP Development Tools

Curl

Fiddler Web Debugger

Wireshark

Desktop Web Browser

Page 24: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Alternatives Nancy

http://nancyfx.org

ServiceStackhttp://servicestack.net

OpenRastahttp://openrasta.org

WCF Web HTTPhttp://goo.gl/IRgM7

Page 25: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

Resources ASP.NET Web API Homepage http://

www.asp.net/web-api

Getting Started With ASP.NET Web APIhttp://bit.ly/IoFApW

ASP.NET CodePlex Repositoryhttp://aspnetwebstack.codeplex.com

Twitter #aspnetwebapi

Page 26: dotNet Miami  - April 19th, 2012: Cecil Phillip: Building HTTP Services with ASP.Net and Web API

THANK YOU


Recommended