SlideShare a Scribd company logo
Web API Basics




     Learn More @ http://www.learnnowonline.com
        Copyright © by Application Developers Training Company
Objectives




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Objectives
• See how REST and web services can be
  used to access data




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Objectives
• See how REST and web services can be
  used to access data
• Build your first Web API service




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
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




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
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


         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service
• Web API Routing




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   What Is ASP.NET Web API?
•   Create Your First Web API Service
•   Web API Routing
•   Create a Web API Service for CRUD
    Operations




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
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



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
What Is ASP.NET Web API?




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
What Is ASP.NET Web API?
• Next iteration of WCF REST




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
What Is ASP.NET Web API?
• Next iteration of WCF REST
• Incorporated into ASP.NET MVC 4




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
What Is ASP.NET Web API?
• Next iteration of WCF REST
• Incorporated into ASP.NET MVC 4
• Framework for developing REST
  oriented services




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
REST




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
REST
• Uses HTTP protocols




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
REST
• Uses HTTP protocols
• URLs and methods




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
REST
• Uses HTTP protocols
• URLs and methods
• Accessible from a wide variety of
  clients




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
REST
• Uses HTTP protocols
• URLs and methods
• Accessible from a wide variety of
  clients
• HTTP methods:




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
REST
• Uses HTTP protocols
• URLs and methods
• Accessible from a wide variety of
  clients
• HTTP methods:
  • GET




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
REST
• Uses HTTP protocols
• URLs and methods
• Accessible from a wide variety of
  clients
• HTTP methods:
  • GET
  • POST



           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
REST
• Uses HTTP protocols
• URLs and methods
• Accessible from a wide variety of
  clients
• HTTP methods:
  • GET
  • POST
  • PUT


           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
GET




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
GET
• Primarily just a URL making a simple
  request for a resource, e.g., a web page




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
GET
• Primarily just a URL making a simple
  request for a resource, e.g., a web page
• Response is sent back




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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:




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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/



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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:

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
POST




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
POST
• Sends collection of name-value pairs
  along with the request




         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




         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)




         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



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
PUT




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
PUT
• Used to store a resource at the
  supplied URL




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
PUT
• Used to store a resource at the
  supplied URL
• Generally used for Editing existing
  resources




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
DELETE




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
DELETE
• Used for deleting resources




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
DELETE
• Used for deleting resources
• Should return an appropriate HTTP
  code




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service
• Web API Routing




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   What Is ASP.NET Web API?
•   Create Your First Web API Service
•   Web API Routing
•   Create a Web API Service for CRUD
    Operations




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
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



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Create Your First Web API




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Create Your First Web API
 • Create a repository




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Create Your First Web API
 • Create a repository
 • Create an API controller to use the
   repository




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Create Your First Web API
 • Create a repository
 • Create an API controller to use the
   repository
 • Try it out in a browser




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service
• Web API Routing




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   What Is ASP.NET Web API?
•   Create Your First Web API Service
•   Web API Routing
•   Create a Web API Service for CRUD
    Operations




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
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



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Web API Routing




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Web API Routing
• Interpretation of URLs by the server to
  decide what code should handle the
  request




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Web API Routing
• Interpretation of URLs by the server to
  decide what code should handle the
  request
• Operates similarly to ASP.NET MVC
  routing




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Web API Routing
• Interpretation of URLs by the server to
  decide what code should handle the
  request
• Operates similarly to ASP.NET MVC
  routing
• Actions determined by HTTP method
  used


          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Default Mapping




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Default Mapping
• Configured in Global.asax




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Default Mapping
• Configured in Global.asax
• Uses “api” as URL segment




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Default Mapping
• Configured in Global.asax
• Uses “api” as URL segment
• Adds word “Controller” to the
  controller part of URL




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
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



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
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
Alternative Routing




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Alternative Routing
• Rarely necessary for most Web API
  services




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Alternative Routing
• Rarely necessary for most Web API
  services
• Several options to change URL routing




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
HTTP Method Attributes




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
HTTP Method Attributes
• Very similar to ASP.NET MVC




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
HTTP Method Attributes
• Very similar to ASP.NET MVC
• Use attributes to bind HTTP methods
  to specific actions




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
HTTP Method Attributes
• Very similar to ASP.NET MVC
• Use attributes to bind HTTP methods
  to specific actions
[HttpGet]




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
HTTP Method Attributes
• Very similar to ASP.NET MVC
• Use attributes to bind HTTP methods
  to specific actions
[HttpGet]
[HttpPost]




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
HTTP Method Attributes
• Very similar to ASP.NET MVC
• Use attributes to bind HTTP methods
  to specific actions
[HttpGet]
[HttpPost]
[HttpPut]



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
HTTP Method Attributes
• Very similar to ASP.NET MVC
• Use attributes to bind HTTP methods
  to specific actions
[HttpGet]
[HttpPost]
[HttpPut]
[HttpDelete]

         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
AcceptVerbs Attribute




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
AcceptVerbs Attribute
• Also used on actions




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
AcceptVerbs Attribute
• Also used on actions
• Specify HTTP methods as strings




         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




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Action Names in the URL




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Action Names in the URL
• Makes URLs route identically to
  ASP.NET MVC




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Action Names in the URL
• Makes URLs route identically to
  ASP.NET MVC
• Must change routeTemplate in
  Global.asax




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Action Names in the URL
• Makes URLs route identically to
  ASP.NET MVC
• Must change routeTemplate in
  Global.asax
• Must also add HTTP method attributes
  to actions



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Removing Actions from




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Removing Actions from
• Used when a resource’s URL would
  trigger an action, but this is not
  desired




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Removing Actions from
• Used when a resource’s URL would
  trigger an action, but this is not
  desired
• Use the NonAction attribute on the
  method




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service
• Web API Routing




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   What Is ASP.NET Web API?
•   Create Your First Web API Service
•   Web API Routing
•   Create a Web API Service for CRUD
    Operations




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
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



        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Create a Web API Service for
CRUD Operations




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Create a Web API Service for
CRUD Operations

• Create – POST




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Create a Web API Service for
CRUD Operations

• Create – POST
• Read – GET




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Create a Web API Service for
CRUD Operations

• Create – POST
• Read – GET
• Update – PUT




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Create a Web API Service for
CRUD Operations

•   Create – POST
•   Read – GET
•   Update – PUT
•   Delete – DELETE




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Create a Web API Service for
CRUD Operations

•   Create – POST
•   Read – GET
•   Update – PUT
•   Delete – DELETE
•   Basic functionality that most services
    will have


           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Create a Web API Service for
CRUD Operations

• Create – POST
• Read – GET
• Update – PUT
• Delete – DELETE
• Basic functionality that most services
  will have
• Try it out!
        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Agenda




     Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
• What Is ASP.NET Web API?
• Create Your First Web API Service
• Web API Routing




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Agenda
•   What Is ASP.NET Web API?
•   Create Your First Web API Service
•   Web API Routing
•   Create a Web API Service for CRUD
    Operations




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
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



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Filtering Data with




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Filtering Data with
• Uses the OData protocol




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Filtering Data with
• Uses the OData protocol
• Special query strings can be used to:




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Filtering Data with
• Uses the OData protocol
• Special query strings can be used to:
  • Filter




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Filtering Data with
• Uses the OData protocol
• Special query strings can be used to:
  • Filter
  • Page




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Filtering Data with
• Uses the OData protocol
• Special query strings can be used to:
  • Filter
  • Page
  • Sort




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Filtering Data with
• Uses the OData protocol
• Special query strings can be used to:
  • Filter
  • Page
  • Sort
  • And more…




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Filter




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Filter
• Condition that evaluates to true or
  false




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Filter
• Condition that evaluates to true or
  false
• Uses OData-specific keywords




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Filter
• Condition that evaluates to true or
  false
• Uses OData-specific keywords
• Must be sendable in a URL




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Order By




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Order By
• Specifies the sort order of returned
  data




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Order By
• Specifies the sort order of returned
  data
• Can sort by multiple properties




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Order By
• Specifies the sort order of returned
  data
• Can sort by multiple properties
• Can specify ASC and DESC sorting




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Paging




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Paging
• Done by using $skip and $top




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Paging
• Done by using $skip and $top
• $skip passes over a number of records




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Paging
• Done by using $skip and $top
• $skip passes over a number of records
• $skip should be set to: page number *
  page size




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
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




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
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



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
There’s More




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
There’s More
• There are other OData query strings




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
There’s More
• There are other OData query strings
• Other query keywords for $filter




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
There’s More
• There are other OData query strings
• Other query keywords for $filter
• www.odata.org




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Learn More!




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Learn More!
• This is an excerpt from a larger course. Visit
  www.learnnowonline.com for the full details!




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company

More Related Content

PPTX
An Introduction To REST API
PPTX
PPT
Introduction to the Web API
PDF
What is REST API? REST API Concepts and Examples | Edureka
PPTX
REST API Design & Development
PPTX
Rest api and-crud-api
PDF
An Introduction to APIs
An Introduction To REST API
Introduction to the Web API
What is REST API? REST API Concepts and Examples | Edureka
REST API Design & Development
Rest api and-crud-api
An Introduction to APIs

What's hot (20)

PPTX
REST-API introduction for developers
PPTX
API Docs with OpenAPI 3.0
PPTX
GRPC.pptx
PPTX
Restful api
PDF
Introdução APIs RESTful
PDF
API for Beginners
PDF
React & GraphQL
PPT
Understanding REST
PDF
APIs, REST e RESTful: O que os programadores precisam saber? - Marcos Echevar...
PPTX
OAuth 2
PPTX
Overview of Rest Service and ASP.NET WEB API
PDF
Api presentation
PPTX
Api types
PPTX
PDF
API : l'architecture REST
PDF
API Basics
PPTX
API Governance in the Enterprise
PPTX
RESTful API - Best Practices
PPTX
Understanding REST APIs in 5 Simple Steps
PPTX
REST & RESTful Web Services
REST-API introduction for developers
API Docs with OpenAPI 3.0
GRPC.pptx
Restful api
Introdução APIs RESTful
API for Beginners
React & GraphQL
Understanding REST
APIs, REST e RESTful: O que os programadores precisam saber? - Marcos Echevar...
OAuth 2
Overview of Rest Service and ASP.NET WEB API
Api presentation
Api types
API : l'architecture REST
API Basics
API Governance in the Enterprise
RESTful API - Best Practices
Understanding REST APIs in 5 Simple Steps
REST & RESTful Web Services
Ad

Viewers also liked (18)

PDF
Enterprise Use Case Webinar – Development Governance with the WSO2 Governance...
PDF
Multi Tenant API management with WSO2 API Manager
PDF
Customizing the API Store & Publisher in WSO2 API Manager
PDF
Introduction to g reg 4.6.0
PPTX
API Management Workshop (at Startupbootcamp Berlin)
PPT
API 101 - Understanding APIs
PDF
An Introduction to the WSO2 API Manager
PPTX
API designing with WSO2 API Manager
PPTX
WSO2 Identity Server 5.3.0 - Product Release Webinar
PDF
WSO2Con USA 2017: Implementing a Modern API Management Solution that Benefits...
PPTX
ASP.NET Web API and HTTP Fundamentals
PDF
C# ASP.NET WEB API APPLICATION DEVELOPMENT
PDF
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...
PDF
WSO2Con USA 2017: Rise to the Challenge with WSO2 Identity Server and WSO2 AP...
PPTX
WSO2Con USA 2017: DevOps Best Practices in 7 Steps
PDF
Best Practices for API Management
PDF
WSO2Con USA 2017: Managing Verifone’s New Payment Device “Carbon” with WSO2’s...
PPT
API Management architect presentation
Enterprise Use Case Webinar – Development Governance with the WSO2 Governance...
Multi Tenant API management with WSO2 API Manager
Customizing the API Store & Publisher in WSO2 API Manager
Introduction to g reg 4.6.0
API Management Workshop (at Startupbootcamp Berlin)
API 101 - Understanding APIs
An Introduction to the WSO2 API Manager
API designing with WSO2 API Manager
WSO2 Identity Server 5.3.0 - Product Release Webinar
WSO2Con USA 2017: Implementing a Modern API Management Solution that Benefits...
ASP.NET Web API and HTTP Fundamentals
C# ASP.NET WEB API APPLICATION DEVELOPMENT
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...
WSO2Con USA 2017: Rise to the Challenge with WSO2 Identity Server and WSO2 AP...
WSO2Con USA 2017: DevOps Best Practices in 7 Steps
Best Practices for API Management
WSO2Con USA 2017: Managing Verifone’s New Payment Device “Carbon” with WSO2’s...
API Management architect presentation
Ad

Similar to Web API Basics (20)

PPTX
Webservices: The RESTful Approach
PPTX
Switch to Backend 2023 | Day 1 Part 1
PPTX
L18 REST API Design
KEY
API Best Practices
PPTX
Http and REST APIs.
PDF
Applicaton Development using RESTful APIs
PDF
Создание API, которое полюбят разработчики. Глубокое погружение
PPTX
Rest WebAPI with OData
PPTX
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
PPTX
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
KEY
Social dev camp_2011
PDF
RESTful web
PDF
Restful web-services
PDF
Restful design at work v2.0
PDF
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
PDF
Modern REST API design principles and rules.pdf
PDF
Great APIs - Future of Your Progress App
PPTX
Will be an introduction to
PDF
API Introduction - API Management Workshop Munich from Ronnie Mitra
PDF
Taking Care of The REST - Creating your own RESTful API Server using Restler 2.0
Webservices: The RESTful Approach
Switch to Backend 2023 | Day 1 Part 1
L18 REST API Design
API Best Practices
Http and REST APIs.
Applicaton Development using RESTful APIs
Создание API, которое полюбят разработчики. Глубокое погружение
Rest WebAPI with OData
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
Social dev camp_2011
RESTful web
Restful web-services
Restful design at work v2.0
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Modern REST API design principles and rules.pdf
Great APIs - Future of Your Progress App
Will be an introduction to
API Introduction - API Management Workshop Munich from Ronnie Mitra
Taking Care of The REST - Creating your own RESTful API Server using Restler 2.0

More from LearnNowOnline (20)

PPT
Windows 8: Shapes and Geometries
PPT
SQL: Permissions and Data Protection
PPT
New in the Visual Studio 2012 IDE
KEY
Attributes, reflection, and dynamic programming
KEY
Asynchronous Programming
KEY
WPF: Working with Data
KEY
WPF Binding
KEY
A tour of SQL Server
KEY
Introducing LINQ
KEY
Generics
KEY
Object oriented techniques
KEY
Object-Oriented JavaScript
KEY
SharePoint Document Management
KEY
SharePoint: Introduction to InfoPath
KEY
Managing site collections
KEY
Web API HTTP Pipeline
KEY
SQL Server: Security
KEY
Sql 2012 development and programming
KEY
What's new in Silverlight 5
KEY
KnockOutJS with ASP.NET MVC
Windows 8: Shapes and Geometries
SQL: Permissions and Data Protection
New in the Visual Studio 2012 IDE
Attributes, reflection, and dynamic programming
Asynchronous Programming
WPF: Working with Data
WPF Binding
A tour of SQL Server
Introducing LINQ
Generics
Object oriented techniques
Object-Oriented JavaScript
SharePoint Document Management
SharePoint: Introduction to InfoPath
Managing site collections
Web API HTTP Pipeline
SQL Server: Security
Sql 2012 development and programming
What's new in Silverlight 5
KnockOutJS with ASP.NET MVC

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Spectral efficient network and resource selection model in 5G networks
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
sap open course for s4hana steps from ECC to s4
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx

Web API Basics

  • 1. Web API Basics Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 2. Objectives Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 3. Objectives • See how REST and web services can be used to access data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 4. Objectives • See how REST and web services can be used to access data • Build your first Web API service Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 5. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 6. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 7. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 8. Agenda • What Is ASP.NET Web API? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 9. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 10. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 11. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing • Create a Web API Service for CRUD Operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 12. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 13. What Is ASP.NET Web API? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 14. What Is ASP.NET Web API? • Next iteration of WCF REST Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 15. What Is ASP.NET Web API? • Next iteration of WCF REST • Incorporated into ASP.NET MVC 4 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 16. What Is ASP.NET Web API? • Next iteration of WCF REST • Incorporated into ASP.NET MVC 4 • Framework for developing REST oriented services Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 17. REST Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 18. REST • Uses HTTP protocols Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 19. REST • Uses HTTP protocols • URLs and methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 20. REST • Uses HTTP protocols • URLs and methods • Accessible from a wide variety of clients Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 21. REST • Uses HTTP protocols • URLs and methods • Accessible from a wide variety of clients • HTTP methods: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 22. REST • Uses HTTP protocols • URLs and methods • Accessible from a wide variety of clients • HTTP methods: • GET Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 23. REST • Uses HTTP protocols • URLs and methods • Accessible from a wide variety of clients • HTTP methods: • GET • POST Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 24. REST • Uses HTTP protocols • URLs and methods • Accessible from a wide variety of clients • HTTP methods: • GET • POST • PUT Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 25. GET Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 26. GET • Primarily just a URL making a simple request for a resource, e.g., a web page Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 27. GET • Primarily just a URL making a simple request for a resource, e.g., a web page • Response is sent back Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 28. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 29. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 30. 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: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 31. 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/ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 32. 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: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 33. POST Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 34. POST • Sends collection of name-value pairs along with the request Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 35. POST • Sends collection of name-value pairs along with the request • Commonly used with forms on the web Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 36. POST • Sends collection of name-value pairs along with the request • Commonly used with forms on the web • Used to add new resources (Insert) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 37. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 38. PUT Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 39. PUT • Used to store a resource at the supplied URL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 40. PUT • Used to store a resource at the supplied URL • Generally used for Editing existing resources Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 41. DELETE Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 42. DELETE • Used for deleting resources Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 43. DELETE • Used for deleting resources • Should return an appropriate HTTP code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 44. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 45. Agenda • What Is ASP.NET Web API? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 46. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 47. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 48. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing • Create a Web API Service for CRUD Operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 49. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 50. Create Your First Web API Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 51. Create Your First Web API • Create a repository Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 52. Create Your First Web API • Create a repository • Create an API controller to use the repository Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 53. Create Your First Web API • Create a repository • Create an API controller to use the repository • Try it out in a browser Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 54. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 55. Agenda • What Is ASP.NET Web API? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 56. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 57. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 58. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing • Create a Web API Service for CRUD Operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 59. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 60. Web API Routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 61. Web API Routing • Interpretation of URLs by the server to decide what code should handle the request Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 62. Web API Routing • Interpretation of URLs by the server to decide what code should handle the request • Operates similarly to ASP.NET MVC routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 63. Web API Routing • Interpretation of URLs by the server to decide what code should handle the request • Operates similarly to ASP.NET MVC routing • Actions determined by HTTP method used Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 64. Default Mapping Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 65. Default Mapping • Configured in Global.asax Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 66. Default Mapping • Configured in Global.asax • Uses “api” as URL segment Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 67. Default Mapping • Configured in Global.asax • Uses “api” as URL segment • Adds word “Controller” to the controller part of URL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 68. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 69. 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
  • 70. Alternative Routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 71. Alternative Routing • Rarely necessary for most Web API services Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 72. Alternative Routing • Rarely necessary for most Web API services • Several options to change URL routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 73. HTTP Method Attributes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 74. HTTP Method Attributes • Very similar to ASP.NET MVC Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 75. HTTP Method Attributes • Very similar to ASP.NET MVC • Use attributes to bind HTTP methods to specific actions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 76. HTTP Method Attributes • Very similar to ASP.NET MVC • Use attributes to bind HTTP methods to specific actions [HttpGet] Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 77. HTTP Method Attributes • Very similar to ASP.NET MVC • Use attributes to bind HTTP methods to specific actions [HttpGet] [HttpPost] Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 78. HTTP Method Attributes • Very similar to ASP.NET MVC • Use attributes to bind HTTP methods to specific actions [HttpGet] [HttpPost] [HttpPut] Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 79. HTTP Method Attributes • Very similar to ASP.NET MVC • Use attributes to bind HTTP methods to specific actions [HttpGet] [HttpPost] [HttpPut] [HttpDelete] Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 80. AcceptVerbs Attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 81. AcceptVerbs Attribute • Also used on actions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 82. AcceptVerbs Attribute • Also used on actions • Specify HTTP methods as strings Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 83. AcceptVerbs Attribute • Also used on actions • Specify HTTP methods as strings • Especially useful for atypical HTTP methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 84. Action Names in the URL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 85. Action Names in the URL • Makes URLs route identically to ASP.NET MVC Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 86. Action Names in the URL • Makes URLs route identically to ASP.NET MVC • Must change routeTemplate in Global.asax Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 87. Action Names in the URL • Makes URLs route identically to ASP.NET MVC • Must change routeTemplate in Global.asax • Must also add HTTP method attributes to actions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 88. Removing Actions from Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 89. Removing Actions from • Used when a resource’s URL would trigger an action, but this is not desired Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 90. Removing Actions from • Used when a resource’s URL would trigger an action, but this is not desired • Use the NonAction attribute on the method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 91. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 92. Agenda • What Is ASP.NET Web API? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 93. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 94. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 95. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing • Create a Web API Service for CRUD Operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 96. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 97. Create a Web API Service for CRUD Operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 98. Create a Web API Service for CRUD Operations • Create – POST Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 99. Create a Web API Service for CRUD Operations • Create – POST • Read – GET Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 100. Create a Web API Service for CRUD Operations • Create – POST • Read – GET • Update – PUT Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 101. Create a Web API Service for CRUD Operations • Create – POST • Read – GET • Update – PUT • Delete – DELETE Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 102. Create a Web API Service for CRUD Operations • Create – POST • Read – GET • Update – PUT • Delete – DELETE • Basic functionality that most services will have Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 103. Create a Web API Service for CRUD Operations • Create – POST • Read – GET • Update – PUT • Delete – DELETE • Basic functionality that most services will have • Try it out! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 104. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 105. Agenda • What Is ASP.NET Web API? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 106. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 107. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 108. Agenda • What Is ASP.NET Web API? • Create Your First Web API Service • Web API Routing • Create a Web API Service for CRUD Operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 109. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 110. Filtering Data with Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 111. Filtering Data with • Uses the OData protocol Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 112. Filtering Data with • Uses the OData protocol • Special query strings can be used to: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 113. Filtering Data with • Uses the OData protocol • Special query strings can be used to: • Filter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 114. Filtering Data with • Uses the OData protocol • Special query strings can be used to: • Filter • Page Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 115. Filtering Data with • Uses the OData protocol • Special query strings can be used to: • Filter • Page • Sort Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 116. Filtering Data with • Uses the OData protocol • Special query strings can be used to: • Filter • Page • Sort • And more… Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 117. Filter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 118. Filter • Condition that evaluates to true or false Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 119. Filter • Condition that evaluates to true or false • Uses OData-specific keywords Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 120. Filter • Condition that evaluates to true or false • Uses OData-specific keywords • Must be sendable in a URL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 121. Order By Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 122. Order By • Specifies the sort order of returned data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 123. Order By • Specifies the sort order of returned data • Can sort by multiple properties Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 124. Order By • Specifies the sort order of returned data • Can sort by multiple properties • Can specify ASC and DESC sorting Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 125. Paging Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 126. Paging • Done by using $skip and $top Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 127. Paging • Done by using $skip and $top • $skip passes over a number of records Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 128. Paging • Done by using $skip and $top • $skip passes over a number of records • $skip should be set to: page number * page size Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 129. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 130. 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 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 131. There’s More Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 132. There’s More • There are other OData query strings Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 133. There’s More • There are other OData query strings • Other query keywords for $filter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 134. There’s More • There are other OData query strings • Other query keywords for $filter • www.odata.org Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 135. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 136. Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company

Editor's Notes