Introduction of HTTP

Introduction of HTTP

·

7 min read

HTTP Methods

HTTP methods indicate the action that the client wishes to perform on the web server resource.

Common HTTP methods are:

HTTP MethodDescription
GETThe client requests a resource on the web server.
POSTThe client submits data to a resource on the web server.
PUTThe client replaces a resource on the web server.
DELETEThe client deletes a resource on the web server.

HTTP Request Body

HTTP requests can optionally include a request body. A request body is often included when using the HTTP POST and PUT methods to transmit data.

POST /users HTTP/1.1
Host: example.com

{
 "key1":"value1",
 "key2":"value2",
 "array1":["value3","value4"]
}
PUT /users/1 HTTP/1.1
Host: example.com
Content-type: text/json

{"key1":"value1"}

HTTP Response Body

Following the HTTP response headers is the HTTP response body. This is the main content of the HTTP response.

This can contain images, video, HTML documents and other media types.

HTTP/1.1 200 OK
Date: Fri, 17 Feb 2023 15:00:00 GMT+2
Server: Apache/2.2.14 (Linux)
Content-Length: 84
Content-Type: text/html

<html>
  <head><title>Test</title></head>
  <body>Test HTML page.</body>
</html>

Have you ever noticed the lock icon

beside the URL in your web browser?

This means the secure version of HTTP is being used.

HTTP is a core operational protocol

of the world wide web.

It is what enables your web browser to

communicate with a web server that hosts a website.

HTTP is the communication protocol

you use whenever you browse the web.

HTTP stands for Hypertext Transfer Protocol

is a protocol used for transferring

web resources such as HTML documents,

images, styles, and other files.

HTTP is a request response-based protocol.

A web browser or client sends

an HTTP request to a server,

and the web server sends

the HTTP response back to the browser.

Next, let's start exploring

the makeup of an HTTP request.

An HTTP request consists of a method,

path, version, and headers.

The HTTP method describes

the type of action that the client was to perform.

The primary or the most commonly used HTTP methods

are GET,

POST, PUT and DELETE.

The GET method is used to

retrieve information from the given server.

The POST request is used to send data to the server.

The PUT method updates

whatever currently exists on the website with

something else and

the DELETE method removes the resource.

The path is the representation of

where the resource is stored on the web server.

For example, if you requested

an image at https://example.com/index.html,

the path would be /index.html.

There are multiple versions of the HTTP protocol.

I won't explore these right now,

but I want you to be aware that Version

1.1 and 2.0 are the most used.

Finally, there are the headers.

Headers contain additional information

about the request,

and the client that is making the request.

For certain requests methods,

the requests will also contain a body

of content that the client is sending.

Now, let's cover some details

about the makeup of an HTTP response.

HTTP responses follow a format

similar to the request format.

Following the header, the response

will optionally contain

a message body consisting of

the response contents such as the HTML document,

the image file, and so forth.

HTTP status codes indicate if

the HTTP requests successfully completed.

The core values are in the range of a

100-599 and grouped by purpose.

The status message is

a text representation of the status code.

During your web browsing,

have you ever encountered pages that display

404 error not found or 500 errors?

The server is not responding?

These are HTTP status codes.

I want to briefly explain to you

the status codes and their grouping.

There are five groups of status codes.

They're grouped by the first digit of the error number.

Informational is grouped from 100-199.

Successful responses are grouped from 200-299.

Redirection messages are from 300-399.

Client error responses ranged from

400-499 and server error responses are from 500- 599.

Information responses are

provisional responses sent by the server.

These responses are interim before the actual response.

The most common inflammation response is 100 Continue,

which indicates that the web client should continue to

request or ignore the response

if the request is already finished.

Successful responses indicate that

the request was successfully processed by the web server,

with the most common success response

being 200 Ok. You're

receiving these responses every day when you

receive content successfully from a website.

The meaning of Ok depends on the HTTP method.

If the method is GET,

it means that the resource is found and is

included in the body of the HTTP response.

If it's POST, it means that

the resource was successfully

transmitted to the web server.

If it's PUT, the resource was

successfully transmitted to the web server.

Finally, if the method is DELETE,

it means the resource was deleted.

Redirection responses indicate to the web client

that the requested resource

has been moved to a different path.

The most common response codes used are

301 Moved Permanently and 302 was Found.

The difference between the redirection messages 301 and

302 is that 302 indicates a temporary redirection.

The resource has been temporarily moved.

When web browsers receive these responses,

they will automatically submit

the request for the resource at the new path.

Client error responses indicate

that the requests contained

bad syntax or content

and cannot be processed by the webserver.

The most common codes used are,

400 is used where the web browser or

client submitted bad data to the web server.

401 is used to indicate that the user

must log into an account

before the request can be processed.

403 is used to indicate the request was valid,

but that the webserver is refusing to process it.

This is often used to indicate that a user does not have

sufficient permissions to execute

an action in a web application.

404 is used to indicate that

the requested resource was not found on the web server.

Server error responses indicate that a failure

occurred on the webserver while

trying to process the request.

The most common code used is 500 Internal Server Error,

which is a generic error status

indicating that the server fail to process the request.

Now, have you ever bought something

online and needed to enter your credit card information?

You wouldn't want someone else to get

this information from the HTTP request.

This is where HTTPS is involved.

HTTPS is the secure version of HTTP.

It is used for secure communication between two computers

so that nobody else can see

the information being sent and received.

It does this by using something called encryption.

We won't cover encryption right now.

Like an HTTP,

the requests and responses still behave

in the same way and have the same content.

The big difference is before the content is sent,

it is turned into a secret code.

Only the other computer can turn

the secret code back into its original content.

If someone else was to look at the code,

it wouldn't be understandable.

You use HTTPS every day.

This is the lock icon you see

beside the URL in your web browser.

Before I finish,

Firstly, it is a protocol

used by web clients and web servers.

It works to transfer web resources such as

HTML files and as

the foundation of any data exchanges on the web.

Also, remember that by using HTTPS,

we send the information securely.

Requests are sent by the client,

usually a web browser,

and the server replies with responses which may be

the return of an image or an HTML page.

HTTP requests have a syntax that includes method,

path, versions, and headers.

HTTP responses follow a similar format to the request.

HTTP status codes indicate whether

the HTTP requests successfully completed.

The status code is a three-digit number that

corresponds with groups representing

different types of results.

Now you know how the HTTP protocol request

and the response cycle works.

You know about its methods and the elements that

make up an HTTP request.