Skip to content

Added mock products API with manual testing support via browser #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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