diff --git a/mock-products-api/app.py b/mock-products-api/app.py new file mode 100644 index 0000000..6065716 --- /dev/null +++ b/mock-products-api/app.py @@ -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/") +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) diff --git a/mock-products-api/requirements.txt b/mock-products-api/requirements.txt new file mode 100644 index 0000000..2077213 --- /dev/null +++ b/mock-products-api/requirements.txt @@ -0,0 +1 @@ +Flask \ No newline at end of file