SlideShare a Scribd company logo
1 of 45
REST WEB SERVICES
Mahek
WHAT IS WEB API?
• API(Application Programming Interface) is a interface between two
software which allows interaction between each other.
• It is a messenger, which receives the request for services, send it to
the server and finally respond it to the client.
• E.g. Consider a restaurant where customer(Client), who orders the
food to the waiter(API), and kitchen room(Server) receives the order
and delivers the food.
RESTAURANT
Client
API
K
i
t
c
h
e
n
WHY API’S?
• We need a service for any device with front end
o Easy
o Simple
o Lightweight
o All features of HTTP
• ReST-ful(Representational State Transfer) Services fulfill all the
above needs.
Need of API’s
INTRODUCTION TO REST
• It is an architectural pattern for developing web services as opposed
to a specification.
• REST architectures are realized by applying specific interaction
constraints such as performance, reliability, scalability, simplicity,
modifiability, visibility and portability.
• Web service API’s that adheres to REST architectural constraints are
RESTful Web API’s
INTRODUCTION TO REST
• REST web services communicate over the HTTP specification, using
HTTP vocabulary:
o Methods (GET, POST, etc.)
o HTTP URI syntax (paths, parameters, etc.)
o Media types (xml, json, html, plain text, etc)
o HTTP Response codes.
INTRODUCTION TO REST
• Representational
o Clients possess the information necessary to identify, modify, and/or delete a
web resource.
• State
o All resource state information is stored on the client.
• Transfer
o Client state is passed from the client to the service through HTTP.
INTRODUCTION TO REST
The six characteristics of REST:
1. Uniform interface
2. Decoupled client-server interaction
3. Stateless
4. Cacheable
5. Layered
6. Extensible through code on demand (optional)
*Services that do not conform to the above required constraints
are not strictly RESTful web services.
HTTP-REST REQUEST BASICS
• The HTTP request is sent from the client.
o Identifies the location of a resource.
o Specifies the verb, or HTTP method to use when accessing the
resource.
o Supplies optional request headers (name-value pairs) that
provide additional information the server may need when
processing the request.
o Supplies an optional request body that identifies additional data to
be uploaded to the server (e.g. form parameters, attachments, etc.)
HTTP-REST REQUEST BASICS
• A typical client GET request:
• A typical client POST request:
POST /save HTTP/1.1
User-Agent: IE
Content-Type: application/x-www-form-urlencoded
[CRLF]
name=x&id=2
Requested Resource (path and query string)
Request Headers
(no request body)
Requested Resource (typically no query string)
Request
Headers
Request Body (e.g. form parameters)
HTTP-REST RESPONSE BASICS
• The HTTP response is sent from the server.
o Gives the status of the processed request.
o Supplies response headers (name-value pairs) that provide
additional information about the response.
o Supplies an optional response body that identifies additional data
to be downloaded to the client (html, xml, binary data, etc.)
HTTP-REST RESPONSE BASICS
• Sample Server Responses:
HTTP/1.1 500 Internal Server Error
HTTP/1.1 201 Created
Location: /view/7
[CRLF]
Some message goes here.
Response StatusHTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1337
[CRLF]
<html>
<!-- Some HTML Content. -->
</html>
Response Headers
Response Body (content)
Response Status
Response Status
Response Header
Response Body
Response Status
HTTP-REST VOCABULARY
HTTP Methods supported by REST:
• GET – Requests a resource at the request URL
o Should not contain a request body, as it will be discarded.
o May be cached locally or on the server.
o May produce a resource, but should not modify on it.
• POST – Submits information to the service for processing
o Should typically return the new or modified resource.
• PUT – Add a new resource at the request URL
• DELETE – Removes the resource at the request URL
• OPTIONS – Indicates which methods are supported
• HEAD – Returns meta information about the request URL
HTTP-REST VOCABULARY
A typical HTTP REST URL:
• The protocol identifies the transport scheme that will be used to process and respond to
the request.
• The host name identifies the server address of the resource.
• The path and query string can be used to identify and customize the accessed resource.
http://my.store.com/fruits/list?category=fruit&limit=20
protocol host name path to a
resource
query string
HTTP AND REST
A REST service framework provides a controller for routing HTTP
requests to a request handler according to:
• The HTTP method used (e.g. GET, POST)
• Supplied path information (e.g /service/listItems)
• Query, form, and path parameters
• Headers, cookies, etc.
ROUTING IN WEB API
Characteristics of routing in Web API:
• We can use API controller names and a naming convention for
actions to route Web API requests
• Alternatively we can use the following attributes to control the
mapping of HTTP requests (HTTP Verb+URL) to actions in the
controller:
• The HttpGet, HttpPut, HttpPost, or HttpDelete attributes
• The AcceptVerbs attribute
• The ActionName attribute
CREATING A WEB API FOR AN MVC 4
WEB APPLICATION
To create a Web API for a an MVC4 application:
1. Implement a Web API template in your project:
o In the New Project dialog box, click ASP.NET MVC 4 Web Application
o In the Select a Template box of the New ASP.NET MVC 4 Project dialog box, click Web
API
2. Add an MVC API controller class to the project:
o Hosts application code for handling requests
o Derives from the ApiController base class
3. Add action methods to the controller class
USING ROUTES AND CONTROLLERS
IN WEB API’S
Routing in ASP.NET MVC4 applications involves the following:
• ASP.NET adds a default route to:
o Map a URL and a controller
o Support the operations of the REST-style Web APIs
• We can modify the default route to include multiple actions in the
same HTTP method
• We can use the WebApiConfig class to:
o Modify the routing
o Enable multiple versions of API to coexist in the same project
DEMO
Implementing Web API
SECURITY
Basically we require two techniques to make our WebApi more
secure:
o Authentication
o Authorization
o Maintaining Session
SECURITY
Basic Authentication
o Basic authentication is a mechanism, where an end user gets
authenticated through our service i.e. RESTful service with the help
of plain credentials such as user name and password.
o An end user makes a request to the service for authentication with
user name and password embedded in request header.
o Service receives the request and checks if the credentials are valid
or not, and returns the response accordingly, in case of invalid
credentials, service responds with 401 error code i.e. unauthorized.
BASIC AUTHENTICATION
SECURITY
Token Based Authorization
o Authorization part comes just after authentication, once
authenticated a service can send a token to an end user through
which user can access other resources.
o The token could be any encrypted key, which only server/service
understands and when it fetches the token from the request made by
end user, it validates the token and authorizes user into the system
o Token can have its own lifetime, and may expire accordingly
TOKEN BASED AUTHORIZATION
MAINTAINING SESSION
• We can maintain sessions using Token based Authorization.
• An authenticated user will be allowed to access resources for a
particular period of time, and can re-instantiate the request with an
increased session time delta to access other resource or the same
resource.
• We may need to implement login/logout for a user, to maintain
sessions for the user, to provide roles and permissions to their user,
all these features could be achieved using basic authentication and
token based authorization.
CACHING
• HTTP caches can store copies of responses
• Useful for reducing:
o Network traffic
o Server workload
o Call latency
• Caches are a main factor for scalability on the web
CACHE-HEADERS
• Cache-Control
o no-cache (Default): Response may be cached, but revalidated on next request
o no-store: Do not store a local copy
o max-age: Set TTL, in seconds
o private: Do not store in proxies
• Expires
o Default value: -1 (expired)
o Specify date of expiration (UTC, up to a year from today)
o max-age takes precedence
• While a resource is cached and hasn’t expired, no request is sent to
the server
CACHING
• ETag (entity tag) contains a resource’s version
• Can be a hash, timestamp, version number, GUID, …
• First time:
Client
sends a request
Server adds ETag
header to response
Client caches
response with ETag
CACHING
• ETag (entity tag) contains a resource’s version
• Can be a hash, timestamp, version number, GUID, …
• Subsequent calls:
Client sends a
request with ETag
Server compares
ETag to resource’s
version
Respond with
HTTP 304
(Unmodified)
Respond with the
updated resource
and Etag
Client caches
response with
ETag
REST SERVICES OVER SOAP
REST is easier to use for the most part and is more flexible. It has the following
advantages when compared to SOAP:
o No expensive tools require to interact with the Web service
o REST is lightweight as compare to SOAP
o Smaller learning curve
o Efficient (SOAP uses XML for all messages, REST can use smaller message formats)
o Fast (no extensive processing required)
o Closer to other Web technologies in design philosophy
ODATA
• Open Data protocol(OData) is an open protocol for sharing data.
• It is built upon AtomPub, itself an extension of Atom Publishing
Protocol.
• Odata is based on REST; therefore a simple web browser can view
the data exposed through an Odata service.
• It not only allows read access but also whole set of CRUD
operations.
HOW ODATA WORKS
• OData has four main parts:
1. OData data model
2. OData protocol
3. OData client libraries
4. OData service
REQUESTING RESOURCES
• As an example we use the service of an open trip management system.
• If a person named Russell White, who has formerly registered at Tripin,
would like to find out who are the other people in it.
INTERNAL WORKING
RESPONSE
REQUESTING RESOURCES
• By Individual resource
url: serviceRoot/People(‘Mahek’)
• By Individual property
url: serviceRoot/Airports(‘IGI’)/Name
• By Individual property Raw Value
url: serviceRoot/Airports(‘IGI’)/Name/$value
QUERYING DATA
• OData supports various kinds of query options for querying data.
• Example:
DATA MODIFICATION
• Creating a resource
Request Response
DATA MODIFICATION
• Deleting a resource
Request : DELETE serviceRoot/People(‘Mahek’)
Response:
HTTP/1.1 204 No Content
DATA MODIFICATION
• Updating a resource
Request Response
DATA MODIFICATION
• Relationships from one entity to another are represented as
navigation properties.
• Example: Here two persons are related by friendship.
DATA MODIFICATION
Invoking Function
• OData supports defining functions to represent complicated logic
which can be frequently used.
• Example
After having explored the TripPin OData service, Russell finds out
that it has a function called GetInvolvedPeople from which he can
find out the involved people of specific trip.
ADVANCED FEATURES
• Singleton
• Derived Entity Type
• Batch
THANK YOU……

More Related Content

What's hot

introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)FabMinds
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServicesPrateek Tandon
 
Httpbasics 1207412539273264-9-converted
Httpbasics 1207412539273264-9-convertedHttpbasics 1207412539273264-9-converted
Httpbasics 1207412539273264-9-convertedcomputerorganization
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocolsFabMinds
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersKevin Hazzard
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoTFabMinds
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocolwanangwa234
 
Understanding the Web through HTTP
Understanding the Web through HTTPUnderstanding the Web through HTTP
Understanding the Web through HTTPOlivia Brundage
 
RESTful modules in zf2
RESTful modules in zf2RESTful modules in zf2
RESTful modules in zf2Corley S.r.l.
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring FrameworkArcadian Learning
 

What's hot (19)

introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)
 
Web services - REST and SOAP
Web services - REST and SOAPWeb services - REST and SOAP
Web services - REST and SOAP
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServices
 
Apache ppt
Apache pptApache ppt
Apache ppt
 
Httpbasics 1207412539273264-9-converted
Httpbasics 1207412539273264-9-convertedHttpbasics 1207412539273264-9-converted
Httpbasics 1207412539273264-9-converted
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 
Server side
Server sideServer side
Server side
 
Web technology Unit-I Part D - message format
Web technology Unit-I  Part D - message formatWeb technology Unit-I  Part D - message format
Web technology Unit-I Part D - message format
 
web connectivity in IoT
web connectivity in IoTweb connectivity in IoT
web connectivity in IoT
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocol
 
OAuth: Trust Issues
OAuth: Trust IssuesOAuth: Trust Issues
OAuth: Trust Issues
 
Understanding the Web through HTTP
Understanding the Web through HTTPUnderstanding the Web through HTTP
Understanding the Web through HTTP
 
Api 101
Api 101Api 101
Api 101
 
RESTful modules in zf2
RESTful modules in zf2RESTful modules in zf2
RESTful modules in zf2
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework
 
Design patternsforiot
Design patternsforiotDesign patternsforiot
Design patternsforiot
 
Fm 2
Fm 2Fm 2
Fm 2
 

Viewers also liked

Rhubee Neale18Dec 2016 CV
Rhubee Neale18Dec 2016 CVRhubee Neale18Dec 2016 CV
Rhubee Neale18Dec 2016 CVRhubee Neale
 
Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...
Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...
Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...Thorne & Derrick International
 
Travel Addicts - Corporate Events
Travel Addicts - Corporate EventsTravel Addicts - Corporate Events
Travel Addicts - Corporate EventsVenuraj Janakarajan
 
Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...
Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...
Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...BDO IT Solutions
 
20161210_新趨勢報告_互聯網醫療保險
20161210_新趨勢報告_互聯網醫療保險20161210_新趨勢報告_互聯網醫療保險
20161210_新趨勢報告_互聯網醫療保險Collaborator
 
2016/3/12 個股研究(寶成)
2016/3/12 個股研究(寶成)2016/3/12 個股研究(寶成)
2016/3/12 個股研究(寶成)Collaborator
 
20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_Blockchain20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_BlockchainCollaborator
 

Viewers also liked (11)

Rhubee Neale18Dec 2016 CV
Rhubee Neale18Dec 2016 CVRhubee Neale18Dec 2016 CV
Rhubee Neale18Dec 2016 CV
 
willemart_reference
willemart_referencewillemart_reference
willemart_reference
 
KU Leuven Reference
KU Leuven ReferenceKU Leuven Reference
KU Leuven Reference
 
Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...
Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...
Using Infra-Red (IR) Heaters To Provide Targeted Energy Efficient Hazardous A...
 
Travel Addicts - Corporate Events
Travel Addicts - Corporate EventsTravel Addicts - Corporate Events
Travel Addicts - Corporate Events
 
Roxtec : Semisubmersibles
Roxtec : SemisubmersiblesRoxtec : Semisubmersibles
Roxtec : Semisubmersibles
 
Alterenergy - Energy Sustainability Planning Recommendation and Guidelines
Alterenergy - Energy Sustainability Planning Recommendation and GuidelinesAlterenergy - Energy Sustainability Planning Recommendation and Guidelines
Alterenergy - Energy Sustainability Planning Recommendation and Guidelines
 
Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...
Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...
Microsoft CRM Features – What’s New with Dynamics CRM 2016? | BDO Connections...
 
20161210_新趨勢報告_互聯網醫療保險
20161210_新趨勢報告_互聯網醫療保險20161210_新趨勢報告_互聯網醫療保險
20161210_新趨勢報告_互聯網醫療保險
 
2016/3/12 個股研究(寶成)
2016/3/12 個股研究(寶成)2016/3/12 個股研究(寶成)
2016/3/12 個股研究(寶成)
 
20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_Blockchain20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_Blockchain
 

Similar to Rest WebAPI with OData

REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API RecommendationsJeelani Shaik
 
Api design and development
Api design and developmentApi design and development
Api design and developmentoquidave
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGSiddharth Sharma
 
Rest webservice ppt
Rest webservice pptRest webservice ppt
Rest webservice pptsinhatanay
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
SCWCD : The web client model : CHAP : 1
SCWCD  : The web client model : CHAP : 1SCWCD  : The web client model : CHAP : 1
SCWCD : The web client model : CHAP : 1Ben Abdallah Helmi
 
restapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdfrestapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdfmrle7
 
Rest API Testing
Rest API TestingRest API Testing
Rest API Testingupadhyay_25
 
Ch 3: Web Application Technologies
Ch 3: Web Application TechnologiesCh 3: Web Application Technologies
Ch 3: Web Application TechnologiesSam Bowne
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesWebStackAcademy
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web ServiceHoan Vu Tran
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesSam Bowne
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service DesignLorna Mitchell
 
Advanced Web Design And Development BIT 3207
Advanced Web Design And Development BIT 3207Advanced Web Design And Development BIT 3207
Advanced Web Design And Development BIT 3207Lori Head
 
0_Leksion_Web_Servers (1).pdf
0_Leksion_Web_Servers (1).pdf0_Leksion_Web_Servers (1).pdf
0_Leksion_Web_Servers (1).pdfZani10
 

Similar to Rest WebAPI with OData (20)

REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
Api design and development
Api design and developmentApi design and development
Api design and development
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
 
Rest webservice ppt
Rest webservice pptRest webservice ppt
Rest webservice ppt
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
SCWCD : The web client model : CHAP : 1
SCWCD  : The web client model : CHAP : 1SCWCD  : The web client model : CHAP : 1
SCWCD : The web client model : CHAP : 1
 
restapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdfrestapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdf
 
Rest API Testing
Rest API TestingRest API Testing
Rest API Testing
 
SCWCD : The web client model
SCWCD : The web client modelSCWCD : The web client model
SCWCD : The web client model
 
Ch 3: Web Application Technologies
Ch 3: Web Application TechnologiesCh 3: Web Application Technologies
Ch 3: Web Application Technologies
 
Ch-1_.ppt
Ch-1_.pptCh-1_.ppt
Ch-1_.ppt
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application Technologies
 
Compute rNetwork.pptx
Compute rNetwork.pptxCompute rNetwork.pptx
Compute rNetwork.pptx
 
Mini-Training: Let's have a rest
Mini-Training: Let's have a restMini-Training: Let's have a rest
Mini-Training: Let's have a rest
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service Design
 
Advanced Web Design And Development BIT 3207
Advanced Web Design And Development BIT 3207Advanced Web Design And Development BIT 3207
Advanced Web Design And Development BIT 3207
 
0_Leksion_Web_Servers (1).pdf
0_Leksion_Web_Servers (1).pdf0_Leksion_Web_Servers (1).pdf
0_Leksion_Web_Servers (1).pdf
 

Recently uploaded

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Rest WebAPI with OData

  • 2. WHAT IS WEB API? • API(Application Programming Interface) is a interface between two software which allows interaction between each other. • It is a messenger, which receives the request for services, send it to the server and finally respond it to the client. • E.g. Consider a restaurant where customer(Client), who orders the food to the waiter(API), and kitchen room(Server) receives the order and delivers the food.
  • 5. • We need a service for any device with front end o Easy o Simple o Lightweight o All features of HTTP • ReST-ful(Representational State Transfer) Services fulfill all the above needs. Need of API’s
  • 6. INTRODUCTION TO REST • It is an architectural pattern for developing web services as opposed to a specification. • REST architectures are realized by applying specific interaction constraints such as performance, reliability, scalability, simplicity, modifiability, visibility and portability. • Web service API’s that adheres to REST architectural constraints are RESTful Web API’s
  • 7. INTRODUCTION TO REST • REST web services communicate over the HTTP specification, using HTTP vocabulary: o Methods (GET, POST, etc.) o HTTP URI syntax (paths, parameters, etc.) o Media types (xml, json, html, plain text, etc) o HTTP Response codes.
  • 8. INTRODUCTION TO REST • Representational o Clients possess the information necessary to identify, modify, and/or delete a web resource. • State o All resource state information is stored on the client. • Transfer o Client state is passed from the client to the service through HTTP.
  • 9. INTRODUCTION TO REST The six characteristics of REST: 1. Uniform interface 2. Decoupled client-server interaction 3. Stateless 4. Cacheable 5. Layered 6. Extensible through code on demand (optional) *Services that do not conform to the above required constraints are not strictly RESTful web services.
  • 10. HTTP-REST REQUEST BASICS • The HTTP request is sent from the client. o Identifies the location of a resource. o Specifies the verb, or HTTP method to use when accessing the resource. o Supplies optional request headers (name-value pairs) that provide additional information the server may need when processing the request. o Supplies an optional request body that identifies additional data to be uploaded to the server (e.g. form parameters, attachments, etc.)
  • 11. HTTP-REST REQUEST BASICS • A typical client GET request: • A typical client POST request: POST /save HTTP/1.1 User-Agent: IE Content-Type: application/x-www-form-urlencoded [CRLF] name=x&id=2 Requested Resource (path and query string) Request Headers (no request body) Requested Resource (typically no query string) Request Headers Request Body (e.g. form parameters)
  • 12. HTTP-REST RESPONSE BASICS • The HTTP response is sent from the server. o Gives the status of the processed request. o Supplies response headers (name-value pairs) that provide additional information about the response. o Supplies an optional response body that identifies additional data to be downloaded to the client (html, xml, binary data, etc.)
  • 13. HTTP-REST RESPONSE BASICS • Sample Server Responses: HTTP/1.1 500 Internal Server Error HTTP/1.1 201 Created Location: /view/7 [CRLF] Some message goes here. Response StatusHTTP/1.1 200 OK Content-Type: text/html Content-Length: 1337 [CRLF] <html> <!-- Some HTML Content. --> </html> Response Headers Response Body (content) Response Status Response Status Response Header Response Body Response Status
  • 14. HTTP-REST VOCABULARY HTTP Methods supported by REST: • GET – Requests a resource at the request URL o Should not contain a request body, as it will be discarded. o May be cached locally or on the server. o May produce a resource, but should not modify on it. • POST – Submits information to the service for processing o Should typically return the new or modified resource. • PUT – Add a new resource at the request URL • DELETE – Removes the resource at the request URL • OPTIONS – Indicates which methods are supported • HEAD – Returns meta information about the request URL
  • 15. HTTP-REST VOCABULARY A typical HTTP REST URL: • The protocol identifies the transport scheme that will be used to process and respond to the request. • The host name identifies the server address of the resource. • The path and query string can be used to identify and customize the accessed resource. http://my.store.com/fruits/list?category=fruit&limit=20 protocol host name path to a resource query string
  • 16. HTTP AND REST A REST service framework provides a controller for routing HTTP requests to a request handler according to: • The HTTP method used (e.g. GET, POST) • Supplied path information (e.g /service/listItems) • Query, form, and path parameters • Headers, cookies, etc.
  • 17. ROUTING IN WEB API Characteristics of routing in Web API: • We can use API controller names and a naming convention for actions to route Web API requests • Alternatively we can use the following attributes to control the mapping of HTTP requests (HTTP Verb+URL) to actions in the controller: • The HttpGet, HttpPut, HttpPost, or HttpDelete attributes • The AcceptVerbs attribute • The ActionName attribute
  • 18. CREATING A WEB API FOR AN MVC 4 WEB APPLICATION To create a Web API for a an MVC4 application: 1. Implement a Web API template in your project: o In the New Project dialog box, click ASP.NET MVC 4 Web Application o In the Select a Template box of the New ASP.NET MVC 4 Project dialog box, click Web API 2. Add an MVC API controller class to the project: o Hosts application code for handling requests o Derives from the ApiController base class 3. Add action methods to the controller class
  • 19. USING ROUTES AND CONTROLLERS IN WEB API’S Routing in ASP.NET MVC4 applications involves the following: • ASP.NET adds a default route to: o Map a URL and a controller o Support the operations of the REST-style Web APIs • We can modify the default route to include multiple actions in the same HTTP method • We can use the WebApiConfig class to: o Modify the routing o Enable multiple versions of API to coexist in the same project
  • 21. SECURITY Basically we require two techniques to make our WebApi more secure: o Authentication o Authorization o Maintaining Session
  • 22. SECURITY Basic Authentication o Basic authentication is a mechanism, where an end user gets authenticated through our service i.e. RESTful service with the help of plain credentials such as user name and password. o An end user makes a request to the service for authentication with user name and password embedded in request header. o Service receives the request and checks if the credentials are valid or not, and returns the response accordingly, in case of invalid credentials, service responds with 401 error code i.e. unauthorized.
  • 24. SECURITY Token Based Authorization o Authorization part comes just after authentication, once authenticated a service can send a token to an end user through which user can access other resources. o The token could be any encrypted key, which only server/service understands and when it fetches the token from the request made by end user, it validates the token and authorizes user into the system o Token can have its own lifetime, and may expire accordingly
  • 26. MAINTAINING SESSION • We can maintain sessions using Token based Authorization. • An authenticated user will be allowed to access resources for a particular period of time, and can re-instantiate the request with an increased session time delta to access other resource or the same resource. • We may need to implement login/logout for a user, to maintain sessions for the user, to provide roles and permissions to their user, all these features could be achieved using basic authentication and token based authorization.
  • 27. CACHING • HTTP caches can store copies of responses • Useful for reducing: o Network traffic o Server workload o Call latency • Caches are a main factor for scalability on the web
  • 28. CACHE-HEADERS • Cache-Control o no-cache (Default): Response may be cached, but revalidated on next request o no-store: Do not store a local copy o max-age: Set TTL, in seconds o private: Do not store in proxies • Expires o Default value: -1 (expired) o Specify date of expiration (UTC, up to a year from today) o max-age takes precedence • While a resource is cached and hasn’t expired, no request is sent to the server
  • 29. CACHING • ETag (entity tag) contains a resource’s version • Can be a hash, timestamp, version number, GUID, … • First time: Client sends a request Server adds ETag header to response Client caches response with ETag
  • 30. CACHING • ETag (entity tag) contains a resource’s version • Can be a hash, timestamp, version number, GUID, … • Subsequent calls: Client sends a request with ETag Server compares ETag to resource’s version Respond with HTTP 304 (Unmodified) Respond with the updated resource and Etag Client caches response with ETag
  • 31. REST SERVICES OVER SOAP REST is easier to use for the most part and is more flexible. It has the following advantages when compared to SOAP: o No expensive tools require to interact with the Web service o REST is lightweight as compare to SOAP o Smaller learning curve o Efficient (SOAP uses XML for all messages, REST can use smaller message formats) o Fast (no extensive processing required) o Closer to other Web technologies in design philosophy
  • 32. ODATA • Open Data protocol(OData) is an open protocol for sharing data. • It is built upon AtomPub, itself an extension of Atom Publishing Protocol. • Odata is based on REST; therefore a simple web browser can view the data exposed through an Odata service. • It not only allows read access but also whole set of CRUD operations.
  • 33. HOW ODATA WORKS • OData has four main parts: 1. OData data model 2. OData protocol 3. OData client libraries 4. OData service
  • 34. REQUESTING RESOURCES • As an example we use the service of an open trip management system. • If a person named Russell White, who has formerly registered at Tripin, would like to find out who are the other people in it.
  • 37. REQUESTING RESOURCES • By Individual resource url: serviceRoot/People(‘Mahek’) • By Individual property url: serviceRoot/Airports(‘IGI’)/Name • By Individual property Raw Value url: serviceRoot/Airports(‘IGI’)/Name/$value
  • 38. QUERYING DATA • OData supports various kinds of query options for querying data. • Example:
  • 39. DATA MODIFICATION • Creating a resource Request Response
  • 40. DATA MODIFICATION • Deleting a resource Request : DELETE serviceRoot/People(‘Mahek’) Response: HTTP/1.1 204 No Content
  • 41. DATA MODIFICATION • Updating a resource Request Response
  • 42. DATA MODIFICATION • Relationships from one entity to another are represented as navigation properties. • Example: Here two persons are related by friendship.
  • 43. DATA MODIFICATION Invoking Function • OData supports defining functions to represent complicated logic which can be frequently used. • Example After having explored the TripPin OData service, Russell finds out that it has a function called GetInvolvedPeople from which he can find out the involved people of specific trip.
  • 44. ADVANCED FEATURES • Singleton • Derived Entity Type • Batch