Web API Basics
Web API Basics
Objectives
See how REST and web services can be used to access data Build your first Web API service Use Web API naming conventions for routing Modify your service for basic CRUD operations Filter your data results with URL parameters
Agenda
What Is ASP.NET Web API? Create Your First Web API Service Web API Routing Create a Web API Service for CRUD Operations Filtering Data with Parameters
REST
Uses HTTP protocols URLs and methods Accessible from a wide variety of clients HTTP methods:
GET
Primarily just a URL making a simple request for a resource, e.g., a web page Response is sent back Additional information is put in a query string Generally used to Select data Selecting all: http://www.root.com/products/ Selecting one: http://www.root.com/products/17
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
POST
Sends collection of name-value pairs along with the request Commonly used with forms on the web Used to add new resources (Insert) Should return an appropriate HTTP success code
PUT
Used to store a resource at the supplied URL Generally used for Editing existing resources
DELETE
Used for deleting resources Should return an appropriate HTTP code
Agenda
What Is ASP.NET Web API? Create Your First Web API Service Web API Routing Create a Web API Service for CRUD Operations Filtering Data with Parameters
Agenda
What Is ASP.NET Web API? Create Your First Web API Service Web API Routing Create a Web API Service for CRUD Operations Filtering Data with Parameters
Default Mapping
Configured in Global.asax Uses api as URL segment Adds word Controller to the controller part of URL Looks for action that begins with the HTTP method Additional URL parameters are mapped as action parameters
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
AcceptVerbs Attribute
Also used on actions Specify HTTP methods as strings Especially useful for atypical HTTP methods
Agenda
What Is ASP.NET Web API? Create Your First Web API Service Web API Routing Create a Web API Service for CRUD Operations Filtering Data with Parameters
Agenda
What Is ASP.NET Web API? Create Your First Web API Service Web API Routing Create a Web API Service for CRUD Operations Filtering Data with Parameters
Sort
And more
Filter
Condition that evaluates to true or false Uses OData-specific keywords Must be sendable in a URL
Order By
Specifies the sort order of returned data Can sort by multiple properties Can specify ASC and DESC sorting
Paging
Done by using $skip and $top $skip passes over a number of records $skip should be set to: page number * page size $top selects a certain number to return $top should be set to page size
Theres More
There are other OData query strings Other query keywords for $filter www.odata.org
Learn More!
This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!