Viva Question Are Based On The Code
Viva Question Are Based On The Code
You said:
GET, POST,
ChatGPT said:
ChatGPT
Here’s an explanation of GET and POST methods commonly used in web development:
GET Method
Purpose: Used to request data from a server. It is primarily used to retrieve
information.
Characteristics:
python
Copy code
@app.route("/search")
def search():
query = request.args.get("query")
return f"Searching for {query}"
POST Method
Purpose: Used to send data to the server for processing, such as submitting a form.
Characteristics:
The data is sent in the body of the HTTP request, making it more secure for
sensitive information.
It does not have size limitations like GET.
POST requests are not idempotent, meaning repeated requests can result in different
outcomes (e.g., submitting a form twice might create two entries).
It cannot be bookmarked or cached by browsers.
Example in Flask:
python
Copy code
@app.route("/submit", methods=["POST"])
def submit():
data = request.form["name"]
return f"Hello, {data}"
Key Differences:
Aspect GET POST
Purpose Retrieve data Submit data
Data Visibility Visible in the URL Hidden in the request body
Data Length Limited Unlimited
Use Case Fetching data (e.g., search) Submitting forms
Both methods are essential in web applications and are used depending on the
specific use case.