What do 'post' and 'get' actually mean/do?

A kind person provided a code to understand how it functions with google, and have the example with a username, password and submit button. When I filled in the fields and clicked submit, ‘get’ took me to google and had my username and password in the address bar whereas ‘post’ came up as ‘inappropriate for google’. Please elaborate on this so that I can understand what is going on.! I attached images to show what I mean and the code is right below.
Here’s there code for reference:

<!DOCTYPE html>
<html>
<head>
	<title>Form Facts</title>
</head>
<body>
	<div>
		<form action="https://www.google.com/" method="get">
			<input type="text" placeholder="enter username" name="Username"><br/>
			<input type="password" placeholder="enter password" name="Password"><br/>
			<input type="submit" name="Submit">
		</form>
		<p>
			After pressing submit,see the address bar and compare.
		</p>
	</div>
</body>
</html>

username


A GET request is the HTTP request you are most familiar with.

Whenever you enter a URL and hit enter, a GET request will be triggered and your browser goes and gets what you asked for.

In the example above, a form is used to change the URL parameters to include the info you put in the form. You could obviously just write that more complicated URL yourself by hand and get the same outcome.

A POST request is still common, but very different. It posts data to a server and the server will do what it has been programmed to do with it.

This is usually used for database interactions.

For example, you fill in your user name and password and POST it to the server. The server looks for your user name and checks your password matches and responds accordingly.

The server has to be expecting a POST request though, or it will just fail. This is usually achieved through routes, but that’s likely more complicated than you need to know for now.

Basically the reason the second example fails is because Google hasn’t set up a route that expects a POST request like the one you are sending.

4 Likes

Those are called HTTP request methods that are sent by any software capable of such thing (cURL, the browser’s XHR mechanism, fetch API, std lib of various languages, Postman, etc).

GET is for asking for resources; it can be a full HTML page, JSON, XML, plain text, video, binary data streams, you name it! The browser issues a GET request to the server when you enter a URL, it can also be done via XHR (the thing that fetch and jquery’s ajax use under the hood).

POST is reserved for sending a new resource (or data in general) to the server so that it can make use if it; regularly for database storage or processing (pdf generation for example). You can send any of the aforementioned type of data to a server, specified in the payload’s Content-Type header.

Can you send data to a server using a GET request? yeah but I wouldn’t advice it since the way you send the data is done via a query-string and it’s not protected by anything so you’re open to your private data (a login attempt for example) being stolen.

For these requests to work, the server’s codebase must listen to these requests and determine if the URL along with all the query parameters matches any specified parsed route (depends on the framework/library) action.

1 Like

Here is bit more reading material for you


1 Like