The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, and hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web. Hypertext is structured text that uses logical links (hyperlinks) between nodes containing text.
💥Why we have to use HTTP?
HTTPS is used
to protect transmitted data from eavesdropping. It is the default
protocol for conducting financial transactions on the web, and can
protect a website's users from censorship by a government or an ISP.
💥The Client/Server Relationship
The Internet is full of clients who ask for various resources (web pages, files, and so on), and servers, who store that information (or know where to get it). When we make an HTTP request, it zips through the Internet until it finds the server that knows how to fulfill that request. Then the server sends a response back to we.
💥REST
client/server relationship is a prerequisite of a set of principles called REST (or Representational State Transfer).
💥RESTful
Every major development language now includes frameworks for building RESTful Web services. As such, it is important for Web developers and architects to have a clear understanding of REST and RESTful services.
A service based on REST is called a RESTful service. REST is not dependent on any protocol, but almost every RESTful service uses HTTP as its underlying protocol.
A RESTful design promises that and more. In general, RESTful services should have following properties and features.
- Representations
- Messages
- URIs
- Uniform interface
- Stateless
- Links between resources
- Caching
💥An API or web service to be RESTful, it must do the following:
👱Separate the client from the server
👱Not hold state between requests (meaning that all the information necessary to respond to a request is available in each individual request; no data, or state, is held by the server from request to request)
👱Use HTTP and HTTP methods (as explained in the next section).
💥Request & Response
Clients send a request to the server, and the server replies with a response. Apart from the actual data, these messages also contain some metadata about the message. It is important to have some background about the HTTP 1.1 request and response formats for designing RESTful Web services.
Example:
GET http://www.w3.org/Protocols/rfc2616/rfc2616.html HTTP/1.1 Host: www.w3.org Accept: text/html,application/xhtml+xml,application/xml; … User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 … Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8,hi;q=0.6 HTTP request<VERB> is one of the HTTP methods like GET , PUT , POST , DELETE , OPTIONS , etc <URI> is the URI of the resource on which the operation is going to be performed <HTTP Version> is the version of HTTP, generally "HTTP v1.1" .<Request Header> contains the metadata as
a collection of key-value pairs of headers and their values. These
settings contain information about the message and its sender like
client type, the formats client supports, format type of the message
body, cache settings for the response, and a lot more information. <Request Body> is the actual message content. In a RESTful service, that's where the representations of resources sit in a message.HTTP response HTTP/1.1 200 OK Date: Sat, 23 Aug 2014 18:31:04 GMT Server: Apache/2 Last-Modified: Wed, 01 Sep 2004 13:24:52 GMT Accept-Ranges: bytes Content-Length: 32859 Cache-Control: max-age=21600, must-revalidate Expires: Sun, 24 Aug 2014 00:31:04 GMT Content-Type: text/html; charset=iso-8859-1 |
HTTP response:
The server returns
<response code>
, which contains the status of the request. This response code is generally the 3-degits HTTP status code. <Response Header>
contains the metadata and settings about the response message.<Response Body>
contains the representation if the request was successful.
No comments:
Post a Comment