0% found this document useful (0 votes)
189 views

Web Api 2.0: BY Amareswara Rao

This document provides an overview of key features in Web API 2.0, including self-hosting, attribute routing, parameter binding, filtering requests, and using IHTTPActionResult to set HTTP status codes. It discusses topics like hosting Web API in IIS or self-hosting in a console app, using attributes to define routes and HTTP verbs, binding parameters from the URL, body or headers, and applying authorization and exception filters.

Uploaded by

Amareswara Rao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

Web Api 2.0: BY Amareswara Rao

This document provides an overview of key features in Web API 2.0, including self-hosting, attribute routing, parameter binding, filtering requests, and using IHTTPActionResult to set HTTP status codes. It discusses topics like hosting Web API in IIS or self-hosting in a console app, using attributes to define routes and HTTP verbs, binding parameters from the URL, body or headers, and applying authorization and exception filters.

Uploaded by

Amareswara Rao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

WEB API 2.

BY
AMARESWARA RAO
INTRODUCTION
WEB API 2.0

Why Web API ?

For building RESTful applications on the .NET Framework

What are the features of WEB API 2.0 ?

Attribute Routing

Self Host

IHTTPActionResult

Filter Overrides

Testability
CONTENTS
WEB API 2.0

Self-Hosted Web API

Web-Hosted Web API

Global vs Attribute Routing

Verb Names/Action Methods

Binding Parameters

Filtering Requests

HTTP Status Codes with IHTTPActionResult


WEB HOSTED WEB API
WEB API 2.0
System.Web.Http.WebHost.dll

Default Hosting Process

App_Startup -> WebApiConfig.cs

Web-hosted Web API only supports a single server and single configuration file.

Global.asax - GlobalConfiguration.Configuration to config


SELF HOSTED WEB API
WEB API 2.0

System.Web.Http.SelfHost.dll

Hosting inside of a console application/GUI application/Windows Service.

NuGet - Microsoft.AspNet.WebApi.SelfHost -> System.Net.Http, System.Web.Http

console app - place the code in main function


VERB NAMES/ACTION METHODS
WEB API 2.0

Verb Names : Get , Post , Put , Delete , Head , Patch , and


Options

Default Verb : POST

[HttpXyz]

Allowed verbs : [AcceptVerb("Get , Post , Put , Delete")]


DELETE

PUT
POST

GET
BINDING PARAMETERS
WEB API 2.0

action method signature and include parameters, complex types/


simple types

simple types -> int/string -> not from the body(model binders are
responsible)

complex types -> class types -> from the body (formatters are
responsible)

Parameter Binding : [ModelBinding],[FromUri],[FromBody]


FILTERING REQUESTS
WEB API 2.0

Filters are now part of the asynchronous pipeline

[AuthorizeAttribute] X [AllowAnonymousAttribute]

AuthorizationFilterAttribute : filter run before any parameter


binding has happened And Authorization filters run before action
filters.

ActionFilterAttribute : filters run after parameter binding has


happened

ExceptionFilterAttribute : new response object


IHTTPACTIONRESULT
WEB API 2.0

IHTTPActionResult

You might also like