MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Handling HTTP Methods (GET, POST, PUT, DELETE)0%
Study Materials
FlaskProgress 0%
1.1What is Flask & WSGI Architecture1.2Virtual Environments & First Flask Application1.3Flask CLI & Environment Configuration
2.1Dynamic URLs & Type Converters2.2Handling HTTP Methods (GET, POST, PUT, DELETE)2.3The Flask Request Object & Data Parsing2.4Response Objects, make_response & Cookies2.5Reverse Routing with url_for, Aborts & Error Handlers
HomeTutorialsFlaskHandling HTTP Methods (GET, POST, PUT, DELETE)
The Flask Request Object & Data Parsing

Handling HTTP Methods (GET, POST, PUT, DELETE)

Beginner12 min read•Updated: 2026-09-16•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

HTTP defines a set of request methods (also known as verbs) indicating the desired action to be performed on a given resource. By default, @app.route() only responds to GET requests. To build interactive web forms or REST APIs, routes must explicitly accept methods.


1. The methods Argument in @app.route

To allow multiple HTTP verbs on a route, supply a list to the methods parameter:

1from flask import Flask, request, jsonify
2 
3app = Flask(__name__)
4 
5@app.route("/api/v1/articles", methods=["GET", "POST"])
6def manage_articles():
7 if request.method == "GET":
8 # Fetch and return list of articles
9 return jsonify([
10 {"id": 1, "title": "Flask Fundamentals"},
11 {"id": 2, "title": "REST APIs with Python"}
12 ]), 200
13 
14 elif request.method == "POST":
15 # Create a new article from request payload
16 data = request.get_json()
17 if not data or "title" not in data:
18 return jsonify({"error": "Title is required"}), 400
19
20 new_article = {"id": 3, "title": data["title"]}
21 return jsonify(new_article), 201

If a client sends an unsupported method (e.g., DELETE to /api/v1/articles), Flask automatically responds with an HTTP 405 Method Not Allowed header containing the allowed verbs.


2. Separate Route Handlers vs Consolidated Handlers

In RESTful design, you can either handle all methods in one view function using if request.method == '...', or separate them using modern route decorators:

1@app.route("/api/v1/articles/<int:article_id>", methods=["GET"])
2def get_article(article_id):
3 return jsonify({"id": article_id, "title": "Sample Article"})
4 
5@app.route("/api/v1/articles/<int:article_id>", methods=["PUT"])
6def update_article(article_id):
7 data = request.get_json()
8 return jsonify({"id": article_id, "updated_title": data.get("title")})
9 
10@app.route("/api/v1/articles/<int:article_id>", methods=["DELETE"])
11def delete_article(article_id):
12 return "", 204

3. Method Semantics Overview

MethodIdempotentSafePrimary PurposeCommon Response Code
GETYesYesRetrieve representation of a resource without side effects200 OK
POSTNoNoSubmit data to create a new subordinate resource201 Created
PUTYesNoReplace the entire target resource with payload200 OK / 204 No Content
PATCHNoNoApply partial modifications to a resource200 OK
DELETEYesNoRemove the target resource permanently204 No Content
HEADYesYesSame as GET, but transfers status line and header section only200 OK
OPTIONSYesYesDescribe communication options for target resource (CORS preflight)204 No Content

4. Automatic HEAD and OPTIONS Handling

Flask handles HEAD and OPTIONS automatically:

  • Whenever you define a GET route, Flask automatically adds HEAD support. If a HEAD request arrives, Flask invokes the route handler, computes headers, but strips the response body before sending.
  • Flask automatically generates an OPTIONS response listing allowed verbs in the Allow HTTP header.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What HTTP methods are permitted by default when @app.route('/test') is defined without the methods argument?
Question 2
What status code does Flask return if a client sends an HTTP DELETE request to a route configured with methods=['GET', 'POST']?
Question 3
What is meant by an "idempotent" HTTP method?
Question 4
Which HTTP status code should be returned after successfully creating a new record via POST?
Question 5
How does Flask inspect the incoming request verb inside a view function?
Next Lesson

The Flask Request Object & Data Parsing

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Dynamic URLs & Type ConvertersThe Flask Request Object & Data Parsing

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Flask with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext