4 Things You Should Know About HTTP Requests

By | 2018-11-27T13:01:08+00:00 November 27th, 2018|Tags: , , , |

In order to perform a good performance test on the HTTP protocol, there is something that you should know about it. Let’s start!

What is an HTTP request?

The Hypertext Transfer Protocol is an application-level protocol for distributed, hypermedia information systems. This is the foundation for data communication for the World Wide Web since 1990. It is a generic and stateless protocol which can be used for other purposes as well as using extensions of its request methods, error codes, and headers.

What makes HTTP a simple but powerful protocol? Here are some examples

  • HTTP is connectionless: The HTTP client, for example, a browser starts an HTTP request and after making that request, the client disconnects from the server. It only waits for a response. Only after the server processes the request, it re-creates the connection with the client to send a response back.
  • HTTP is media independent: Any type of data(file, binary, text,etc..) can be sent by HTTP. The only thing necessary is that server and client should know how to handle that request.
  • HTTP is stateless: We mentioned that it is connectionless protocol. So being a stateless protocol is a result of it. The server and client are aware of each other only during a current request.

1. HTTP Request Types

GET

The GET method is used to retrieve information from the server using a given URI. Requests using GET should only retrieve data. It should do any data manipulation or any write action.

POST

A POST request is used to send data to the server. It creates data on the server side. It can upload textual information, as well as files of any other media types.

PUT

Put method changes the data stored on the server side with the uploaded content.

DELETE

It removes all the current representations of the target data.

There is some important terminology when working with HTTP like Content-Type, Content-Encoding, Headers, etc. By using all of them, we can only create a complete request. Let’s deep dive into them.

2. Header

HTTP headers are additional information sent with the request or the response. It defines information about payload, client information and what’s expected from a server. According to that information, the server creates the response body.

Some request header values are below:

  • Accept-Encoding
  • Authorization
  • Content-Length
  • Accept

Example: Some web apps might receive or send the response body as XML or JSON file according to the values set in the header.  So you need to set “Accept” attribute to “application/json” or “ application/xml”.

3. Cookies

An HTTP cookie is a very small data sent from a web application. Cookies are stored on the user’s computer by the user’s web browser while the user is browsing. Cookies are the reliable mechanism for websites to remember stateful information. (How do you think e-commerce websites remember what items are in your art even after 3 days). Cookies have an expiration date or a max-age attribute. Those attributes define the last date the web app recognize your user.  You may want to set domain and path attributes so that cookies are valid only under that scope. This is the trickiest part when you work with JMeter on web apps having authorization.

4. Caching

Caching is a technique that allows to store a copy of a given resource. When a web cache has a requested resource in its store, it returns the copy (cached response) instead of re-downloading from the server once again. This brings some benefits of course. A server doesn’t need to serve all clients itself as storing it helps distribute some resource. It improves performance by being closer to the client by using browser cache. It takes less time to transmit the resource. Cache has also some attributes like Cookies. Cache’s max-age attribute defines the last date an object is considered as fresh or rotten.

After understanding those basic structures, you can design and implement better performance tests with JMeter by using HTTP Sampler, HTTP Cache Manager, HTTP Header Manager, and HTTP Cookie Manager.

Happy load testing!