KEMBAR78
Web 7 | HTTP Request and Response | PDF
Mohammad Imam Hossain, Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com
1. Different HTTP Methods:
OPTIONS
 The OPTIONS method represents a request for information about the communication options available on
the request/response chain identified by the Request-URI. This method allows the client to determine the options
and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action
or initiating a resource retrieval.
GET
 The GET method means retrieve whatever information is identified by the Request-URI. The response to a GET
request is cacheable if and only if it meets the requirements for HTTP caching policy. The query string is sent with
the URL of a Get request. This kind of requests can be bookmarked, remain in the browser history and has size
limitations (2KB ~ 8KB). GET requests are idempotent meaning produce same outcomes for the same requests.
POST
 The POST method is used to request that the origin server accept the entity enclosed in the request as a new
subordinate of the resource identified by the Request-URI in the Request-Line. Responses to this method are not
cacheable.
In web services, POST requests are used to send data to the API sever to create or update a resource. The data
sent to the server is stored in the request body of the HTTP request.
Responses to this method are generally not cacheable and this type of requests have no size restrictions. POST
requests are non-idempotent meaning it mutates data on the backend server.
PUT
 The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-
URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the
one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is
capable of being defined as a new resource by the requesting user agent, the origin server can create the
resource with that URI.
Simlar to POST, PUT requests are used to send data to the API to create or update a resource. The difference is
that PUT requests are idempotent. That is, calling the same PUT request multiple times will always produce the
same result. In contrast, calling a POST request repeatedly make have side effects of creating the same resource
multiple times.
DELETE
 The DELETE method requests that the origin server delete the resource identified by the Request-URI.
Responses to this method are not cacheable.
2. HTTP Request Configuration:
Mohammad Imam Hossain, Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com
Example:
3. HTTP Response Configuration:
Example:
4. HTTP Response Status Codes:
The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request. The
Reason-Phrase is intended to give a short textual description of the Status-Code.
The first digit of the Status-Code defines the class of response. There are 5 classes:
Mohammad Imam Hossain, Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com
- 1xx: Informational - Request received, continuing process
- 2xx: Success - The action was successfully received, understood, and accepted
- 3xx: Redirection - Further action must be taken in order to complete the request
- 4xx: Client Error - The request contains bad syntax or cannot be fulfilled
- 5xx: Server Error - The server failed to fulfill an apparently valid request
Some of the status codes are given below,
Status Code Reason-Phrase Status Code Reason Phrase
100 Continue 400 Bad Request
200 OK 403 Forbidden
201 Created 404 Not Found
202 Accepted 500 Internal Server Error
204 No Content 503 Service Unavailable
301 Moved Permanently 505 HTTP Version not supported
5. Web Services vs Web API
Web Service API
A Web service facilitates interaction between two
machines over a network.
An API acts as an interface between two different
applications so that they can communicate with each
other.
An API is a method by which the third-party vendors can
write programs that interface easily with other
programs.
“HTTP” is the most commonly used protocol for
communication.
Web service also uses SOAP as a means of
communication.
API may use any means of communication to initiate
interaction between applications.
A Web service is merely an API wrapped in HTTP. An API exactly defines the methods for
one software program to interact with the other. When
this action involves sending data over a network, Web
services come into the picture. An API generally involves
calling functions from within a software program.
A Web service might not contain a complete set of
specifications and sometimes might not be able to
perform all the tasks that may be possible from a
complete API.
An API consists of a complete set of rules and
specifications for a software program to follow in order
to facilitate interaction.
There are mainly two ways to build Web Services:
"SOAP","REST"
The APIs can be exposed in a number of ways which
include: COM objects, DLL and .H files in C/C++
programming language, JAR files or RMI in
Java, XML over HTTP, JSON over HTTP, etc.
6. Monolithic Architecture:
Monolithic means composed all in one piece. Monolithic software is designed to be self-contained; components of
the program are interconnected and interdependent rather than loosely coupled as is the case with modular
software programs. In a tightly-coupled architecture, each component and its associated components must be
present in order for code to be executed or compiled.
It is simple to develop, test and deploy. The main benefit of this architecture is that it makes the horizontal scaling
simple.
Mohammad Imam Hossain, Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com
Problems:
Applications become too large and complex to fully understand and make changes fast. You must redeploy the
entire application on each update. Bug in any module can potentially bring down the entire process. Changes in
framework or languages will affect the entire application.
7. Micro Service Architecture:
Microservices - also known as the microservice architecture - is an architectural style that structures an application
as a collection of services that are
 Highly maintainable and testable
 Loosely coupled
 Independently deployable
 Organized around business capabilities
 Owned by a small team
Mohammad Imam Hossain, Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com
It reduces the complexity by decomposing application into a set of manageable services which are much faster to
develop, much easier to understand and maintain. It enables each service to be developed and deployed
independently. It also enables each service to be scaled independently.
8. CDN – Content Delivery Network:
CDN stands for “Content Delivery Network” and the
technology provides a way of serving assets such as
static HTML, CSS, Javascript, and images over the web
much faster than serving them from a single origin
server. It works by distributing the content across many
“cache” servers around the world so that users end up
downloading assets from the “cache” servers instead of
the origin server.
To minimize the distance between the visitors and your
website’s server, a CDN stores a cached version of its
content in multiple geographical locations (a.k.a., points
of presence, or PoPs). Each PoP contains a number of
caching servers responsible for content delivery to
visitors within its proximity.
9. Load Balancer:
LB helps to spread the traffic across a cluster of servers to improve responsiveness and availability of applications,
websites or databases. LB also keeps track of the status of all the resources while distributing requests. If a server is
not available to take new requests or is not responding or has elevated error rate, LB will stop sending traffic to such
a server.
We can add LBs at three places:
 Between the user and the web server
 Between web servers and an internal platform layer, like application servers or cache servers
Mohammad Imam Hossain, Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com
 Between internal platform layer and database.
10. Web Scaling:
Any system that can continuously evolve in order to support the growing amount of work is considered to be
scalable.
A system may have to scale because of many reasons like increased data volume or increased amount of
transactions. There exists two types of scaling.
Horizontal and Vertical scaling: Horizontal scaling means that you scale by adding more servers into your pool of
resources whereas Vertical scaling means that you scale by adding more power (CPU, RAM, Storage, etc.) to an
existing server.

Web 7 | HTTP Request and Response

  • 1.
    Mohammad Imam Hossain,Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com 1. Different HTTP Methods: OPTIONS  The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval. GET  The GET method means retrieve whatever information is identified by the Request-URI. The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching policy. The query string is sent with the URL of a Get request. This kind of requests can be bookmarked, remain in the browser history and has size limitations (2KB ~ 8KB). GET requests are idempotent meaning produce same outcomes for the same requests. POST  The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. Responses to this method are not cacheable. In web services, POST requests are used to send data to the API sever to create or update a resource. The data sent to the server is stored in the request body of the HTTP request. Responses to this method are generally not cacheable and this type of requests have no size restrictions. POST requests are non-idempotent meaning it mutates data on the backend server. PUT  The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request- URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. Simlar to POST, PUT requests are used to send data to the API to create or update a resource. The difference is that PUT requests are idempotent. That is, calling the same PUT request multiple times will always produce the same result. In contrast, calling a POST request repeatedly make have side effects of creating the same resource multiple times. DELETE  The DELETE method requests that the origin server delete the resource identified by the Request-URI. Responses to this method are not cacheable. 2. HTTP Request Configuration:
  • 2.
    Mohammad Imam Hossain,Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com Example: 3. HTTP Response Configuration: Example: 4. HTTP Response Status Codes: The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request. The Reason-Phrase is intended to give a short textual description of the Status-Code. The first digit of the Status-Code defines the class of response. There are 5 classes:
  • 3.
    Mohammad Imam Hossain,Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com - 1xx: Informational - Request received, continuing process - 2xx: Success - The action was successfully received, understood, and accepted - 3xx: Redirection - Further action must be taken in order to complete the request - 4xx: Client Error - The request contains bad syntax or cannot be fulfilled - 5xx: Server Error - The server failed to fulfill an apparently valid request Some of the status codes are given below, Status Code Reason-Phrase Status Code Reason Phrase 100 Continue 400 Bad Request 200 OK 403 Forbidden 201 Created 404 Not Found 202 Accepted 500 Internal Server Error 204 No Content 503 Service Unavailable 301 Moved Permanently 505 HTTP Version not supported 5. Web Services vs Web API Web Service API A Web service facilitates interaction between two machines over a network. An API acts as an interface between two different applications so that they can communicate with each other. An API is a method by which the third-party vendors can write programs that interface easily with other programs. “HTTP” is the most commonly used protocol for communication. Web service also uses SOAP as a means of communication. API may use any means of communication to initiate interaction between applications. A Web service is merely an API wrapped in HTTP. An API exactly defines the methods for one software program to interact with the other. When this action involves sending data over a network, Web services come into the picture. An API generally involves calling functions from within a software program. A Web service might not contain a complete set of specifications and sometimes might not be able to perform all the tasks that may be possible from a complete API. An API consists of a complete set of rules and specifications for a software program to follow in order to facilitate interaction. There are mainly two ways to build Web Services: "SOAP","REST" The APIs can be exposed in a number of ways which include: COM objects, DLL and .H files in C/C++ programming language, JAR files or RMI in Java, XML over HTTP, JSON over HTTP, etc. 6. Monolithic Architecture: Monolithic means composed all in one piece. Monolithic software is designed to be self-contained; components of the program are interconnected and interdependent rather than loosely coupled as is the case with modular software programs. In a tightly-coupled architecture, each component and its associated components must be present in order for code to be executed or compiled. It is simple to develop, test and deploy. The main benefit of this architecture is that it makes the horizontal scaling simple.
  • 4.
    Mohammad Imam Hossain,Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com Problems: Applications become too large and complex to fully understand and make changes fast. You must redeploy the entire application on each update. Bug in any module can potentially bring down the entire process. Changes in framework or languages will affect the entire application. 7. Micro Service Architecture: Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are  Highly maintainable and testable  Loosely coupled  Independently deployable  Organized around business capabilities  Owned by a small team
  • 5.
    Mohammad Imam Hossain,Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com It reduces the complexity by decomposing application into a set of manageable services which are much faster to develop, much easier to understand and maintain. It enables each service to be developed and deployed independently. It also enables each service to be scaled independently. 8. CDN – Content Delivery Network: CDN stands for “Content Delivery Network” and the technology provides a way of serving assets such as static HTML, CSS, Javascript, and images over the web much faster than serving them from a single origin server. It works by distributing the content across many “cache” servers around the world so that users end up downloading assets from the “cache” servers instead of the origin server. To minimize the distance between the visitors and your website’s server, a CDN stores a cached version of its content in multiple geographical locations (a.k.a., points of presence, or PoPs). Each PoP contains a number of caching servers responsible for content delivery to visitors within its proximity. 9. Load Balancer: LB helps to spread the traffic across a cluster of servers to improve responsiveness and availability of applications, websites or databases. LB also keeps track of the status of all the resources while distributing requests. If a server is not available to take new requests or is not responding or has elevated error rate, LB will stop sending traffic to such a server. We can add LBs at three places:  Between the user and the web server  Between web servers and an internal platform layer, like application servers or cache servers
  • 6.
    Mohammad Imam Hossain,Lecturer, dept. of CSE, UIU. Email: imambuet11@gmail.com  Between internal platform layer and database. 10. Web Scaling: Any system that can continuously evolve in order to support the growing amount of work is considered to be scalable. A system may have to scale because of many reasons like increased data volume or increased amount of transactions. There exists two types of scaling. Horizontal and Vertical scaling: Horizontal scaling means that you scale by adding more servers into your pool of resources whereas Vertical scaling means that you scale by adding more power (CPU, RAM, Storage, etc.) to an existing server.