Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions mock-products-api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from flask import Flask, jsonify

app = Flask(__name__)

products = [
{"id": 1, "name": "Laptop", "price": 1200},
{"id": 2, "name": "Smartphone", "price": 800},
{"id": 3, "name": "Headphones", "price": 150}
]

@app.route("/")
def home():
return "Welcome to the Mock Products API!"

@app.route("/products")
def get_products():
return jsonify(products)

@app.route("/products/<int:product_id>")
def get_product(product_id):
for product in products:
if product["id"] == product_id:
return jsonify(product)
return jsonify({"error": "Product not found"}), 404

if __name__ == "__main__":
app.run(port=5000)
1 change: 1 addition & 0 deletions mock-products-api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask