HTTP is one of the many concepts a Java Engineer should know.
Since Java is mostly suited for server-side operations, understanding the concept behind HTTP will be valuable during your role as a Java Engineer.
What is HTTP?
HTTP stands for Hyper Text Transfer Protocol.
It's a stateless request-response protocol.
HTTP is an application layer protocol designed to transfer information between networked devices and runs on top of other layers of the network protocol stack.[Cloudflare]
What does stateless mean?
Stateless means that each request is independent of another.
HTTP being stateless plays a significant role in how software engineers design web applications.
An example of a stateless transaction would be doing a search online to answer a question youve thought of. You type your question into a search engine and hit enter. If your transaction is interrupted or closed accidentally, you just start a new one. Think of stateless transactions as a vending machine: a single request and a response. [Red Hat]
What are the advantages of a stateless HTTP?
HTTP being stateless:
Simplifies server design.
Reduces the demand on server resources because we don't need storage to track clients (although most servers will log traffic).
As soon as a request is fulfilled, the connection drops.
The server doesn't preserve unused connections.
HTTP stateless protocol allows each server thread to manage other requests continually.
The ability to handle multiple requests allows the scale of many clients, and each request is guaranteed to be serviced.
This independence simplifies the assembly of pages from multiple resources (such as images, media, etc.).
Resources can come from different origins, and load can be distributed across multiple servers.
HTTP requests being cached:
Improve the speed of response to the user.
Reduces network and server loads, allowing the Web to scale.
HTTP being stateless will enable applications to be resilient to network failure.
Since the connections drop once the request has been fulfilled, a network glitch won't cause a loss of state. This advantage is crucial for mobile applications.
Related: Java Interview Questions
GET vs POST
GET and POST are highly used types of HTTP requests.
GET request:
Appends name-value pairs to the URL.
It's considered safe.
It's the default behaviour of clients and proxies to cache responses.
URL can be easily bookmarked.
POST request:
Sends name-value pairs after the HTTP header.
It's considered to be unsafe because the response cannot be cached.
It can carry a larger payload.
State Preservation
State preservation means how data gets stored when performing an HTTP request.
It happens in three basic variations:
Cookies
Store a small amount of information on the client.
Sent to the server at each HTTP request.
Session variables
- A unique identifier associates information stored on the server with a particular client.
Passing data at each request-response cycle
Store information on the web page.
Appending data to a URL.
Hidden fields in HTML forms.
Related : Why We Need Architectural Design In Software Engineering
Key Takeaways
In this article, you've learned:
What HTTP is.
What stateless means.
The advantages of a stateless HTTP.
GET vs POST requests.
Basic variations of state preservation.
If you found this article helpful, you can subscribe to my FREE weekly newsletter.
Until next time!
🙋🏾
Top comments (2)
Near the beginning, you state: "Java is a purely server-side language". That is a false statement.
I can see why you'd say that. I should rephrase and say that it's mostly suited for server-side operations.