Python Backend #2: Build a Simple REST API with Flask (GET & POST Tutorial)
2.1K views on YouTube
π― Python Web Backend Series (Part 2/6)
Previous Project file https://github.com/NDCSwift/Swift-Projects/raw/refs/heads/main/Python-Projects/PythonBackEnd1_app.py.zip
Now that your Flask server is running, letβs turn it into a real API! In this video, weβll create GET and POST routes and learn how to return and accept structured JSON data using Flask.
Postman:
{
“name”: “Headphones”,
“price”: 79.99
}
Curl:
curl -X POST http://127.0.0.1:5000/products \
-H “Content-Type: application/json” \
-d ‘{“name”: “Headphones”, “price”: 99.99}’
Test Your API With:
Postman: https://www.postman.com/
VS Code REST Client Extension (optional)
π§ What Youβll Learn:
β
How to define routes using Flask decorators
β
Returning JSON using jsonify()
β
Accepting POST data with request.get_json()
β
Using status codes (e.g., 201 Created)
β
Testing with Postman or cURL
π₯ Download My Project Files
π Get the source code here:
π https://ndcswift.github.io/Swift-Projects/
β±οΈ Timestamps:
00:00 β Intro & Recap
00:10 β What we’re building
00:40 β Creating a GET route
01:33 β Adding products
03:06 β Refactoring code + Testing Products
04:20 β Creating a POST route
06:45 β Code 201
07:35 β importing requests
07:51 β Testing Our Program with Curl
10:11 β Testing Our Program with Postman
11:47 β Bonus: Viewing the changes on our webserver
13:35 β Wrap up + what’s next