0% found this document useful (0 votes)
4 views28 pages

HTTP && REST

The document provides an overview of HTTP and REST, explaining the Internet as a network of computer systems using standard protocols. It details various HTTP methods (GET, POST, PUT, DELETE, etc.), status codes, headers, cookies, and the principles of REST as an architectural style. Additionally, it offers tips for designing RESTful APIs and highlights the differences between REST and SOAP.

Uploaded by

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

HTTP && REST

The document provides an overview of HTTP and REST, explaining the Internet as a network of computer systems using standard protocols. It details various HTTP methods (GET, POST, PUT, DELETE, etc.), status codes, headers, cookies, and the principles of REST as an architectural style. Additionally, it offers tips for designing RESTful APIs and highlights the differences between REST and SOAP.

Uploaded by

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

HTTP & REST

What is Internet?
Internet
Network of computer systems which communicate with
each other to exchange information through standard set of
protocols.

One such protocol is HTTP


HTTP(Hypertext Transfer Protocol)
Hypertext: Text served on the internet
containing hyperlinks to other resources

Multimedia: Hypertext and graphics, audio


and video
ech tee tee pee
Hypertext Transfer Protocol
Application layer ( layer wa ??? )
stateless ( New Zealand )
connectionless or connection oriented
HTTP Methods
GET
Requests a representation of the specified resource. Requests using GET should only retrieve data
and should have no other effect. But nobody adheres to this on the web ...

curl http://httpbin.org/get -v

POST
Requests that the server accept the entity enclosed in the request as a new subordinate of the web
resource identified by the URI.

curl --data "param1=value1&param2=value2" "http://httpbin.org/post" -v


HTTP (text protocol)
tsunami-box$ telnet localhost 80

GET /index.php HTTP/1.1


User-Agent: user-agent
Host: localhost:80
Accept: */*

HTTP/1.1 200 OK
Date: Fri, 04 Jul 2014 11:04:20 GMT
Server: Apache/2.2.22 (Ubuntu)
Last-Modified: Fri, 26 Apr 2013 11:52:07 GMT
ETag: "1e20b4-b1-4db422a19aa97"
Accept-Ranges: bytes
Content-Length: 177
Vary: Accept-Encoding
Content-Type: text/html
X-Pad: avoid browser bug

<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
HTTP METHODS
THATS IT RIGHT ???

YA RIGHT !!!
HEAD
Asks for the response identical to the one that would correspond to a GET request, but without the
response body. This is useful for retrieving meta-information written in response headers, without
having to transport the entire content.
curl http://httpbin.org/get -v -I

PUT
Requests that the enclosed entity be stored under the supplied URI. If the URI refers to an already
existing resource, it is modified; if the URI does not point to an existing resource, then the server can
create the resource with that URI. [Idempotent]

curl -X PUT -d arg=val -d arg2=val2 "http://httpbin.org/put" -v


HTTP METHODS
● DELETE
○ Deletes the specified resource. [Idempotent]
● TRACE
○ Echoes back the received request so that a client can see what (if any) changes or
additions have been made by intermediate servers.
● OPTIONS
○ Returns the HTTP methods that the server supports for the specified URL. This can be
used to check the functionality of a web server by requesting '*' instead of a specific
resource.
● CONNECT
○ Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate
SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.
● PATCH
○ Is used to apply partial modifications to a resource.
HTTP Status Codes
● Successful – 2xx
● Redirection – 3xx
● Client Error – 4xx
● Server Error – 5xx

http://www.restapitutorial.com/httpstatuscodes.html
Headers
Operating parameters of transaction
● Common Request Headers
○ Host
○ Content-Type
○ Content-Length
○ User-Agent
● Common Response Headers
○ Date
○ Content-Type
○ Set-Cookie
○ Content-Encoding
curl -H "Accept-Encoding: gzip,deflate" "http://www.theverge.com/" -I -vN
Caching Headers
http://www.mobify.com/blog/beginners-guide-to
-http-cache-headers/
Caching Headers
● Reduces network traffic
● Reduces load time
● Cache expiry headers
○ Expires
○ Cache-Control: max-age (overrides Expires)
● There are only two hard things in Computer Science:
cache invalidation and naming things. (Phil Karlton)
● Resource version in URL
Conditional Headers
● Last-Modified
● ETag
● Conditional GET
○ If-Modified-Since
○ If-None-Match
○ If-Range
Cookies
● Small pieces of data stored on client and
sent on every request
● Use Cases:
○ Session management
○ Personalization
○ Tracking
Cookies
● Can be set both through headers and with JS
● Cookie attributes
○ Path
○ Expires
○ Secure
○ Domain
○ HttpOnly
● Set-Cookie Header
○ MyCookie=ChocoChip; Expires=Wed, 09 Jun 2021 10:18:14 GMT
● Authentication
● HTTPS - TLS Handshake
● Content Negotiation
○ Accept, Accept-Language
● Proxies
○ Forward & Reverse Proxies
● Optimizations???
● CDN …
Web API
● Allows access to data without scrapping
● HTTP + Definition of response format
● Allows multiple interfaces to your application
● SOA
● SOAP and REST
SOAP
● Simple Object Access Protocol
○ yeah very SIMPLE
● Defines an entire protocol on top of other
application protocols
● Supports only XML
● Reads cannot be cached
● Requires special tools to create a client
● Generally worse performance
REST
Representational state transfer. Defined by Roy Fielding in 2000. He
was also a principal author of HTTP 1.0 & 1.1

Wiki says :
REST is an architectural style consisting of a coordinated set of
architectural constraints applied to components, connectors, and data
elements, within a distributed hypermedia system. REST ignores the
details of component implementation and protocol syntax in order to
focus on the roles of components, the constraints upon their interaction
with other components, and their interpretation of significant data
elements
REST
http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
● 6 Constraints
○ Client-Server (Separation of concerns)
○ Stateless (state should be addressable by URL)
○ Cacheable
○ Layered system
○ Code on Demand (Optional)
○ Uniform Interface
Checkout:
https://speakerdeck.com/cprerovsky/rest-in-pea
ce-number-devoxxpl-2016-talk

https://dev.twitter.com/rest/reference
tips
1. Endpoint Naming - Use plurals GET /nodes
2. HTTP verbs - CRUD : POST-GET-PUT-DELETE
3. Subresources
4. Data formats : Decide for one output format
5. Models and Resources
6. Status codes
7. Path Parameters and resources
8. API versioning
9. State
10. Id’s
11. REST clients
RMM
http://www.infoq.com/news/2010/03/RESTLevels
More on Level 3
HATEOAS :
https://en.wikipedia.org/wiki/HATEOAS

Self Study :
http://www.slideshare.net/josdirksen/rest-from-g
et-to-hateoas
REST spec sheet design

BUILD A TODO APP


NOW YOU GUYS CAN REST !!!

You might also like