Skip to content

Basics

HTTP stands for Hypertext Transfer Protocol, and HTTP is the communication protocol used for browsing the web. This protocol uses a message based model where your client makes an HTTP request to a web server and that server responds with a resource which is displayed in the browser.

URL

The URL (Uniform Resource Locator) is probably the most known concept of the Web. It is also one of most important and useful concepts. URL is a web address used to identify resources on the Web.

  • Protocol — Most often they are HTTP (or HTTPS for a secure version of HTTP).
  • Domain — Name that is used to identify one or more IP addresses where the resource is located.
  • Path — Specifies the resource location on the server. It uses the same logic as a resource location used on the device you are reading (i.e. /search/cars/VWBeetle.pdf or C:/my cars/VWBeetle.pdf).
  • Parameters — Additional data used to identify or filter the resource on the server.

Methods

In HTTP, every request must have an URL address. Additionally, request needs a method.

The four main HTTP methods are:

  • GET
  • PUT
  • POST
  • DELETE

These methods directly correspond to actions:

  • read
  • update
  • create
  • delete

Most common methods are GET and POST, however there are more of them.

  • GET — used to request data from a specified resource where data is not modified it in any way as GET requests do not change the state of resource.
  • POST — used to send data to a server to create a resource.
  • PUT — method to update existing resource on a server by using the content in body of the request.
  • DELETE — The DELETE method deletes the specified resource.
  • HEAD — this method has the same function as GET method but with a difference that the return of a HEAD method should not contain body in the response. However, the return will contain same headers as if GET was used. HEAD method is used to check if the resource is present prior of making a GET request.
  • TRACE — method designed for diagnostic purposes. Response will contain in its body the exact content of the request message.
  • OPTIONS — this method is used to describe the communication options (HTTP methods) that are available for the target resource.
  • PATCH — The PATCH method is used to apply partial modifications to a resource.

Example

All HTTP messages have one or more headers, followed by a optional message body. The body contains the data that will be sent with the request or the data received with the response.

First part of every HTTP request holds three items:

GET /adds/search-result?item=vw+beetle HTTP/1.1

When a URL contains a “?” sign means it contains a query. That means it sends parameters of the requested resource.

  1. First part is a method which tells which HTTP method is used. Most commonly used is the GET method. GET method retrieves a resource from the web server and since GET doesn’t have a message body nothing after the header is needed.
  2. Second part is a requested URL.
  3. Third part is a HTTP version being used. Version 1.1. is the most common version for most browsers, however, version 2.0 is taking over.

There are also some other interesting things in a HTTP request:

  • Referer header — tell the URL from which the request has originated.
  • User-Agent header — additional information about the browser being used to generate the request.
  • Host header — uniquely identify a host name, it is necessary when multiple web pages are hosted on the same server.
  • Cookie header — submit additional parameters to the client.

Status codes

HTTP status codes are the defacto language for describing results of the requests browsers (clients) make to servers. Browsers know what the status codes mean, so they know how to present information to you after you make a request.

When you think about it, it makes sense to have defined ways for the server to tell the browser the outcome of a request it made. There are different kinds of browser and different kinds of server configurations to suit specific application needs. If there was no standard communication pattern…

Every time you click on a link or type in a URL and press “Enter” your browser sends a request to a web server. The web server receives and processes the request, and then sends back the requested resources along with an HTTP header.

HTTP status codes are delivered to your browser in the HTTP header. While status codes are returned every single time your browser requests a web page or resource, most of the time you don’t see them. It’s when something goes wrong that you might see an HTTP status code displayed in your browser. It’s the server’s way of saying: “Something isn’t right. Here’s a code that explains what went wrong.”

I’d urge you to pay attention here, especially if you have not had to build APIs before. Understanding how the browser talks to the server (client-server relationship) in a network will help you make sense of why each status code is important.

A proper understanding of these status codes makes all the difference in the user experience of your application. Understanding them means you can efficiently design your application to handle errors or issues that may arise gracefully.

If you are a developer building an API, you can more easily send the appropriate responses for the scenarios your users encounter as they use your application. This is equally very important in building useful applications.

IANA's Hypertext Transfer Protocol (HTTP) Status Code Registry page is the official source for HTTP status codes.

Five categories of HTTP status codes exist; these are the three major groups:

2xx Success

This class of status codes indicates the action requested by the client was received, understood, accepted and processed successfully.

Most of the common codes you will encounter are 200 (OK), 201 (Created) and 204 (No Content)

4xx Client Error

This group of HTTP status codes includes those where the request for a web page or other resource contains bad syntax or cannot be filled for some other reason, presumably by the fault of the client (the web surfer).

Some common client error HTTP status codes include 404 (Not Found), 403 (Forbidden), and 400 (Bad Request).

5xx Server Error

This group of HTTP status codes includes those where the request for a web page or other resource is understood by the website's server but is incapable of filling it for some reason.

Some common server error HTTP status codes include the ever popular 500 (Internal Server Error), along with 504 (Gateway Timeout), 503 (Service Unavailable), and 502 (Bad Gateway).


Further reading