You are on page 1of 21

HTTP RESPONSE

AND REQUEST
CIT 210 - Web Systems & Technologies
HTTP MESSAGES
Four HTTP Messages
● Connection - establishes a connection between the client and the
server
● Request - asks for a resource
● Response - delivers the resource
● Close - terminates the connection
HTTP REQUESTS
HTTP Requests
● HTTP specifies a collection of request methods to specify what
action is to be performed on a particular resource.
● Although they can also be nouns, these request methods are
sometimes referred to as HTTP verbs.
● The most commonly used HTTP request methods are GET, POST,
PUT, PATCH, and DELETE.
● These are equivalent to the CRUD operations (create, read, update,
delete)
Common HTTP Request Methods
● GET: GET request is used to read/retrieve data from a web server.
GET returns an HTTP status code of 200 (OK) if the data is
successfully retrieved from the server.
● POST: POST request is used to send data (file, form data, etc.) to the
server. On successful creation, it returns an HTTP status code of
201.
● PUT: A PUT request is used to modify the data on the server. It
replaces the entire content at a particular location with data that is
passed in the body payload. If there are no resources that match the
request, it will generate one.
HTTP Requests
● PATCH: PATCH is similar to PUT request, but the only difference is,
it modifies a part of the data. It will only replace the content that
you want to update.
● DELETE: A DELETE request is used to delete the data on the server
at a specified location.
HTTP RESPONSES
HTTP Responses
● You search for anything on Google, and by this, a request is being
sent to the server, then the server responds.
● This response is done using HTTP (HyperText Transfer Protocol) by
the server.
● There can be two cases – the server may respond with the
information it has, or else it may show an error with a code.
● Whenever there’s an error in the back end, the server responds
with an error code that explains what error could have happened.
HTTP Responses
● The HTTP status code is a response made by the server to the
client’s request.
● These are three-digit codes and there are more than 60 error status
codes.
HTTP Status Codes
● 1xx – Informational Response. These status codes are all about the
information received by the server when a request is made.
● 2xx – Success. This status code depicts that the request made has
been fulfilled by the server and the expected response has been
achieved.
● 3xx – Redirection. The requested URL is redirected elsewhere.
● 4xx – Client Errors. This indicates that the page is not found.
● 5xx – Server Errors. A request made by the client but the server fails
to complete the request.
COMMON HTTP
STATUS CODES
200 (Success/OK)
● The HTTP status code 200 represents success which means the
page you have requested has been fetched.
● The action made has been accepted and has been delivered to the
client by delivering the requested page.
301 (Permanent Redirect)
● The HTTP status code 301 means that the page you have requested
has moved to a new URL and which is permanent.
● In the future, whenever the user requests the same website, it will
be redirected to the new URL.
● The modified permanent URL is given by the location filed in
response.
302 (Temporary Redirect)
● The requested URL has been redirected to another website
temporarily.
● Further changes in the URL might be made in the future.
● Therefore, this same URL should be used by the client in future
requests.
● Other than GET or HEAD, if the 302 is received in response to a
request, the redirection is temporarily redirected to another
website.
304 (Not Modified)
● HTTP status code 304 is used for caching purposes.
● It tells the client that the response has not been modified, so the
client can continue to use the same cached version of the response.

400 (Bad Request)


● When the client requests a page and the server is not able to
understand anything, it displays a 400 HTTP status code.
● The client SHOULD NOT repeat the request without any changes.
The request can be a malformed, deceptive request routing, or
invalid request.
401 (Unauthorized Error)
● Although the HTTP standard specifies "unauthorized", semantically
this response means "unauthenticated".
● That is, the client must authenticate itself to get the requested
response.

403 (Forbidden)
● The client does not have access rights to the content; that is, it is
unauthorized, so the server is refusing to give the requested resource.
● Unlike 401 Unauthorized, the client's identity is known to the server.
404 (Not Found)
● The server cannot find the requested resource.
● In the browser, this means the URL is not recognized.
● In an API, this can also mean that the endpoint is valid but the
resource itself does not exist.
● Servers may also send this response instead of 403 Forbidden to
hide the existence of a resource from an unauthorized client.
● This response code is probably the most well known due to its
frequent occurrence on the web.
500 (Internal Server Error)
● 500 HTTP status code means requesting a URL is not fulfilled
because the server encounters an unexpected condition.
● The server has encountered a situation it does not know how to
handle.
● It gives information about the request made if it is successful, and
throws an error.
● When there’s an error during a connection to the server, and the
requested page cannot be accessed then this message is displayed.
501 (Not Implemented)
● When a request is made by the client, the server is not able to
recognize the request method and is not able to support any
resource.
● The request method is not supported by the server and cannot be
handled.
● The only methods that servers are required to support (and
therefore that must not return this code) are GET and HEAD.
References

● https://www.geeksforgeeks.org/different-kinds-of-http-requests/

● https://www.geeksforgeeks.org/10-most-common-http-status-codes/

● https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

● https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

You might also like