SlideShare a Scribd company logo
iFour ConsultancyASP.NET MVC Web API
 ASP.NET Web API
 Why ASP.NET MVC Web API?
 ASP.NET Web API Features
 ASP.NET Web API Design
 ASP.NET MVC Web API
 Routing Table
 Error & Exception Handling
 Model Validation
INDEX
http://www.ifourtechnolab.com/ C# Software Development Companies India
 Framework for building and consuming HTTP services that can reach a broad range of
clients including browsers, phones and tablets
 Use XML or JSON or something else with API. JSON is nice for mobile apps with slow
connections
 For example: Call an API from jQuery and better utilize the client's machine and browser
What is ASP.NET Web API?
http://www.ifourtechnolab.com/ C# Software Development Companies India
 It is built for all the other, non-human interactions website or service needs to support.
Think about jQuery code that's making an Ajax request, or a service interface that supports
a mobile client
 In these cases, the requests are coming from code and expect some kind of structured
data and specific HTTP Status Codes
These two are very complimentary, but different enough that trying to build out HTTP
services using ASP.NET MVC took a lot of work to get right
Why ASP.NET MVC Web API?
http://www.ifourtechnolab.com/ C# Software Development Companies India
 Modern HTTP programming model
 Directly access and manipulate HTTP requests and responses in Web APIs using a new, strongly
typed HTTP object model
 Full support for routes
 Web APIs now support the full set of route capabilities that have always been a part of the Web
stack, including route parameters and constraints
 Additionally, mapping to actions has full support for conventions, so no longer need to apply
attributes such as [HttpPost] to your classes and methods
 Filters
 Web APIs now supports filters, including well-known filters such as the [Authorize] attribute
ASP.NET Web API Features
http://www.ifourtechnolab.com/ C# Software Development Companies India
 Content negotiation
 The client and server can work together to determine the right format for data being returned
from an API
 Provide default support for XML, JSON, and Form URL-encoded formats, and extend this support
by adding your own formatters
 Model binding and validation: Model binders provide an easy way to extract data from various
parts of an HTTP request and convert those message parts into .NET objects which can be used
by the Web API actions
 Improved testability of HTTP details
 Rather than setting HTTP details in static context objects, Web API actions can now work with
instances of HttpRequestMessage and HttpResponseMessage
 Generic versions of these objects also exist to work with custom types in addition to the HTTP
types
ASP.NET Web API Features (Cont.)
http://www.ifourtechnolab.com/ C# Software Development Companies India
 Query composition
 By simply returning IQueryable<t>, Web API will support querying via the OData URL
conventions
 Improved Inversion of Control (IoC) via DependencyResolver
 Web API now uses the service locator pattern implemented by MVC’s dependency resolver to
obtain instances for many different facilities
 Code-based configuration
 Web API configuration is accomplished solely through code, leaving config files clean
 Self-host
 Web APIs can be hosted in own process in addition to IIS while still using the full power of routes
and other features of Web API
ASP.NET Web API Features (Cont.)
http://www.ifourtechnolab.com/ C# Software Development Companies India
 The client is whatever consumes the web API (browser, mobile app, and so forth)
 A model is an object that represents the data in application. In this case, the only model is
a to-do item. Models are represented as simple C# classes (POCOs)
 A controller is an object that handles HTTP requests and creates the HTTP response
ASP.NET Web API Design
http://www.ifourtechnolab.com/ C# Software Development Companies India
 MVC : Model -> View -> Controller
 Create a Model
 Create a Controller
ASP.NET MVC Web API
http://www.ifourtechnolab.com/ C# Software Development Companies India
 It is defined, by default, as api/{controller}/{id} where action is defined by an HTTP method
(in global.asax Application_Start method)
Routing Table
HTTP Method URI Path Action Performed
GET /api/products Get All Products
GET /api/products/id Get Product by Id
GET /api/products?category=category Get Products by Category
POST /api/products Insert Product
PUT /api/products/id Update Product
DELETE /api/products/id Delete Product
http://www.ifourtechnolab.com/ C# Software Development Companies India
The four main HTTP methods are mapped to CRUD operations:
 Get retrieves the representation of the resource at a specified URI. GET should have no side
effects on server
 PUT updates a resource at a specified URI
 POST Create a new resource. The server assigns the URI for the new object and returns this URI
as part of the response message
 DELETE deletes a resource at a specified URI
Routing Table
http://www.ifourtechnolab.com/ C# Software Development Companies India
ASP.NET MVC Web API - Example
APIs for crud operation for products
http://www.ifourtechnolab.com/ C# Software Development Companies India
 Response messages, errors and exceptions are translated to HTTP response status codes
 For example:
 POST request should reply with HTTP status 201 (created)
 DELETE request should reply with HTTP status 204 (no content)
 But:
 If a PUT/GET request is done with an invalid id, it should reply with HTTP status 404 (not found)
 Or if a PUT request has invalid model, it can reply with HTTP status 400 (bad request)
Error & Exception Handling
http://www.ifourtechnolab.com/ C# Software Development Companies India
 By default, all .NET exceptions are translated into an HTTP response with status code 500
(internal error)
 It is possible to register Exception filters:
Error & Exception Handling (Cont.)
http://www.ifourtechnolab.com/ C# Software Development Companies India
 Like MVC, Web API supports Data Annotations
(System.ComponentModel.DataAnnotations)
Model Validation
http://www.ifourtechnolab.com/ C# Software Development Companies India
Model Validation - Example
http://www.ifourtechnolab.com/ C# Software Development Companies India
 Create a FilterAttribute
 Add it to Filters in Global.asax Application_Start
Model Validation - FilterAttribute
http://www.ifourtechnolab.com/ C# Software Development Companies India
 https://www.tutorialspoint.com/asp.net_mvc/asp.net_mvc_web_api.htm
 https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-
your-first-web-api
 http://www.c-sharpcorner.com/uploadfile/4d9083/how-to-create-web-api-in-asp-net-
mvc/
References
http://www.ifourtechnolab.com/ C# Software Development Companies India
Questions?
http://www.ifourtechnolab.com/ C# Software Development Companies India

More Related Content

PPTX
PPTX
Mvc by asp.net development company in india - part 2
PPTX
MVC Training Part 2
PPTX
MVC Training Part 1
PPTX
ASP.NET MVC Performance
PPT
Entity frameworks101
PDF
Progressive EPiServer Development
PPTX
More object oriented development with Page Type Builder
Mvc by asp.net development company in india - part 2
MVC Training Part 2
MVC Training Part 1
ASP.NET MVC Performance
Entity frameworks101
Progressive EPiServer Development
More object oriented development with Page Type Builder

What's hot (20)

PPT
Tumbleweed intro
PPTX
Angular jS Introduction by Google
 
PPTX
Azure rev002
PPTX
ASP.NET Presentation
PDF
Introduction To CodeIgniter
PPTX
CodeIgniter 101 Tutorial
PPT
Microsoft Azure
PDF
Rest web service
PDF
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
PDF
Spring mvc
PPTX
MVC - Introduction
PPT
ASP.NET 05 - Exception Handling And Validation Controls
PDF
Oracle ADF 11g Tutorial
PPTX
PDF
Reactjs Basics
PPT
Csphtp1 20
PDF
Spring boot jpa
PDF
C sharp and asp.net interview questions
PPT
Getting Started with Zend Framework
Tumbleweed intro
Angular jS Introduction by Google
 
Azure rev002
ASP.NET Presentation
Introduction To CodeIgniter
CodeIgniter 101 Tutorial
Microsoft Azure
Rest web service
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Spring mvc
MVC - Introduction
ASP.NET 05 - Exception Handling And Validation Controls
Oracle ADF 11g Tutorial
Reactjs Basics
Csphtp1 20
Spring boot jpa
C sharp and asp.net interview questions
Getting Started with Zend Framework
Ad

Viewers also liked (20)

PDF
C# ASP.NET WEB API APPLICATION DEVELOPMENT
PPTX
ASP.NET WEB API Training
PPTX
Integration Tales: Logic & API apps to the rescue!
PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - W...
PPTX
ASP.NET MVC 5 et Web API 2
PPTX
Building HTTP APIs with ASP.NET Core
PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
PPTX
ADO.NET by ASP.NET Development Company in india
PDF
SpringPeople Building Web Sites with ASP.NET MVC FRAMEWORK
PPTX
ASP.NET Core MVC + Web API with Overview
PPTX
3-TIER ARCHITECTURE IN ASP.NET MVC
PPT
Excellent rest using asp.net web api
PPT
ASP.NET MVC Presentation
PPTX
Toi uu hoa he thong 30 trieu nguoi dung
PPTX
PPT
MVC ppt presentation
PPT
ASP.NET 09 - ADO.NET
PPTX
ADO.NET -database connection
PPTX
Introduction to ASP.NET
PPTX
ASP.NET Web API and HTTP Fundamentals
C# ASP.NET WEB API APPLICATION DEVELOPMENT
ASP.NET WEB API Training
Integration Tales: Logic & API apps to the rescue!
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - W...
ASP.NET MVC 5 et Web API 2
Building HTTP APIs with ASP.NET Core
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
ADO.NET by ASP.NET Development Company in india
SpringPeople Building Web Sites with ASP.NET MVC FRAMEWORK
ASP.NET Core MVC + Web API with Overview
3-TIER ARCHITECTURE IN ASP.NET MVC
Excellent rest using asp.net web api
ASP.NET MVC Presentation
Toi uu hoa he thong 30 trieu nguoi dung
MVC ppt presentation
ASP.NET 09 - ADO.NET
ADO.NET -database connection
Introduction to ASP.NET
ASP.NET Web API and HTTP Fundamentals
Ad

Similar to Web API with ASP.NET MVC by Software development company in india (20)

PPTX
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
PDF
Unleash the power of HTTP with ASP.NET Web API
PPTX
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
PDF
ASP.NET Web API Interview Questions By Scholarhat
PPTX
ASP.NET Mvc 4 web api
PPTX
Implementation web api
PDF
Complete guidance book of Asp.Net Web API
PPTX
Web API or WCF - An Architectural Comparison
PPTX
Asp.net web api
PPTX
Will be an introduction to
PDF
Difference between asp.net web api and asp.net mvc
PPTX
C# web api
PPTX
Api design part 1
PPTX
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
PDF
API Introduction - API Management Workshop Munich from Ronnie Mitra
PDF
Creating web api and consuming- part 1
PPTX
Improving Perceived Page Performance with ASP.NET Web API and AJAX
PPTX
06 web api
PPTX
Web api
PDF
Past, Present and Future of APIs of Mobile and Web Apps
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
Unleash the power of HTTP with ASP.NET Web API
CodeCamp Iasi 10 March 2012 - Gabriel Enea - ASP.NET Web API
ASP.NET Web API Interview Questions By Scholarhat
ASP.NET Mvc 4 web api
Implementation web api
Complete guidance book of Asp.Net Web API
Web API or WCF - An Architectural Comparison
Asp.net web api
Will be an introduction to
Difference between asp.net web api and asp.net mvc
C# web api
Api design part 1
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
API Introduction - API Management Workshop Munich from Ronnie Mitra
Creating web api and consuming- part 1
Improving Perceived Page Performance with ASP.NET Web API and AJAX
06 web api
Web api
Past, Present and Future of APIs of Mobile and Web Apps

More from iFour Institute - Sustainable Learning (9)

PPTX
Project Management : Project Planning by iFour Technolab Pvt. Ltd.
PPTX
Project management : Project Monitoring and Control by iFour Technolab Pvt. Ltd.
PPTX
Project management : Causal analysis and Resolution by iFour Technolab Pvt. ...
PPTX
Here are proven techniques to Organizing effective training by iFour Technola...
PPTX
MVC by asp.net development company in india
PPTX
PPTX
jQuery for web development
PPTX
Cascading style sheets - CSS
PPTX
HTML Basics by software development company india
Project Management : Project Planning by iFour Technolab Pvt. Ltd.
Project management : Project Monitoring and Control by iFour Technolab Pvt. Ltd.
Project management : Causal analysis and Resolution by iFour Technolab Pvt. ...
Here are proven techniques to Organizing effective training by iFour Technola...
MVC by asp.net development company in india
jQuery for web development
Cascading style sheets - CSS
HTML Basics by software development company india

Recently uploaded (20)

PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPT
Introduction Database Management System for Course Database
PPTX
L1 - Introduction to python Backend.pptx
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ai tools demonstartion for schools and inter college
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Transform Your Business with a Software ERP System
PDF
top salesforce developer skills in 2025.pdf
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
System and Network Administraation Chapter 3
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Introduction Database Management System for Course Database
L1 - Introduction to python Backend.pptx
ManageIQ - Sprint 268 Review - Slide Deck
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
Transform Your Business with a Software ERP System
top salesforce developer skills in 2025.pdf
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
System and Network Administraation Chapter 3
Which alternative to Crystal Reports is best for small or large businesses.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems

Web API with ASP.NET MVC by Software development company in india

  • 2.  ASP.NET Web API  Why ASP.NET MVC Web API?  ASP.NET Web API Features  ASP.NET Web API Design  ASP.NET MVC Web API  Routing Table  Error & Exception Handling  Model Validation INDEX http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 3.  Framework for building and consuming HTTP services that can reach a broad range of clients including browsers, phones and tablets  Use XML or JSON or something else with API. JSON is nice for mobile apps with slow connections  For example: Call an API from jQuery and better utilize the client's machine and browser What is ASP.NET Web API? http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 4.  It is built for all the other, non-human interactions website or service needs to support. Think about jQuery code that's making an Ajax request, or a service interface that supports a mobile client  In these cases, the requests are coming from code and expect some kind of structured data and specific HTTP Status Codes These two are very complimentary, but different enough that trying to build out HTTP services using ASP.NET MVC took a lot of work to get right Why ASP.NET MVC Web API? http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 5.  Modern HTTP programming model  Directly access and manipulate HTTP requests and responses in Web APIs using a new, strongly typed HTTP object model  Full support for routes  Web APIs now support the full set of route capabilities that have always been a part of the Web stack, including route parameters and constraints  Additionally, mapping to actions has full support for conventions, so no longer need to apply attributes such as [HttpPost] to your classes and methods  Filters  Web APIs now supports filters, including well-known filters such as the [Authorize] attribute ASP.NET Web API Features http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 6.  Content negotiation  The client and server can work together to determine the right format for data being returned from an API  Provide default support for XML, JSON, and Form URL-encoded formats, and extend this support by adding your own formatters  Model binding and validation: Model binders provide an easy way to extract data from various parts of an HTTP request and convert those message parts into .NET objects which can be used by the Web API actions  Improved testability of HTTP details  Rather than setting HTTP details in static context objects, Web API actions can now work with instances of HttpRequestMessage and HttpResponseMessage  Generic versions of these objects also exist to work with custom types in addition to the HTTP types ASP.NET Web API Features (Cont.) http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 7.  Query composition  By simply returning IQueryable<t>, Web API will support querying via the OData URL conventions  Improved Inversion of Control (IoC) via DependencyResolver  Web API now uses the service locator pattern implemented by MVC’s dependency resolver to obtain instances for many different facilities  Code-based configuration  Web API configuration is accomplished solely through code, leaving config files clean  Self-host  Web APIs can be hosted in own process in addition to IIS while still using the full power of routes and other features of Web API ASP.NET Web API Features (Cont.) http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 8.  The client is whatever consumes the web API (browser, mobile app, and so forth)  A model is an object that represents the data in application. In this case, the only model is a to-do item. Models are represented as simple C# classes (POCOs)  A controller is an object that handles HTTP requests and creates the HTTP response ASP.NET Web API Design http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 9.  MVC : Model -> View -> Controller  Create a Model  Create a Controller ASP.NET MVC Web API http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 10.  It is defined, by default, as api/{controller}/{id} where action is defined by an HTTP method (in global.asax Application_Start method) Routing Table HTTP Method URI Path Action Performed GET /api/products Get All Products GET /api/products/id Get Product by Id GET /api/products?category=category Get Products by Category POST /api/products Insert Product PUT /api/products/id Update Product DELETE /api/products/id Delete Product http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 11. The four main HTTP methods are mapped to CRUD operations:  Get retrieves the representation of the resource at a specified URI. GET should have no side effects on server  PUT updates a resource at a specified URI  POST Create a new resource. The server assigns the URI for the new object and returns this URI as part of the response message  DELETE deletes a resource at a specified URI Routing Table http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 12. ASP.NET MVC Web API - Example APIs for crud operation for products http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 13.  Response messages, errors and exceptions are translated to HTTP response status codes  For example:  POST request should reply with HTTP status 201 (created)  DELETE request should reply with HTTP status 204 (no content)  But:  If a PUT/GET request is done with an invalid id, it should reply with HTTP status 404 (not found)  Or if a PUT request has invalid model, it can reply with HTTP status 400 (bad request) Error & Exception Handling http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 14.  By default, all .NET exceptions are translated into an HTTP response with status code 500 (internal error)  It is possible to register Exception filters: Error & Exception Handling (Cont.) http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 15.  Like MVC, Web API supports Data Annotations (System.ComponentModel.DataAnnotations) Model Validation http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 16. Model Validation - Example http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 17.  Create a FilterAttribute  Add it to Filters in Global.asax Application_Start Model Validation - FilterAttribute http://www.ifourtechnolab.com/ C# Software Development Companies India
  • 18.  https://www.tutorialspoint.com/asp.net_mvc/asp.net_mvc_web_api.htm  https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial- your-first-web-api  http://www.c-sharpcorner.com/uploadfile/4d9083/how-to-create-web-api-in-asp-net- mvc/ References http://www.ifourtechnolab.com/ C# Software Development Companies India

Editor's Notes

  • #2: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #4: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #5: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #6: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #7: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #8: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #9: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #10: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #11: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #12: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #13: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #14: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #15: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #16: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #17: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #18: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #19: Software Outsourcing Company India - http://www.ifourtechnolab.com/
  • #20: Software Outsourcing Company India - http://www.ifourtechnolab.com/