![]() |
VOOZH | about |
HTTP methods define how a client (browser) interacts with a server in a web application. They are used to handle different types of requests like fetching data, sending data or updating resources. Common HTTP Methods are:
GET method is used to request data from a server. It appends data to the URL in a name-value pair format. It should not be used for sensitive data since URLs are visible in browser history.
Example: We'll build a Flask app that takes a number as input, calculates its square and displays the result. Our app will have three files:
app.py
Explanation:
squarenum.html
answer.html
Run the application and visit development server:
On clicking the Calculate button one can notice, the value entered, appended, to the URL and the output displayed.
POST method is used to send data to the server for processing. Unlike GET, it does not append data to the URL. Instead, it sends data in the request body, making it a better choice for sensitive or large data.
Example: We will modify our previous Flask app to use POST instead of GET. The app will have the same three files the only changes are made in the app.py and squarenum.html file.
app.py
Explanation:
squarenum.html
Run the application and visit development server:
On clicking the Calculate button, data is posted back to the server and the result page is rendered. Please note, the value entered is not visible in the URL now as the method used, is POST.
To know more, refer to this article GET vs POST