API Endpoints
/products
Description: Fetch detailed product information based on various criteria.
Parameteres:
keyword (string): Search term to find products.
category (string): Filter by specific product categories.
sort (string): Sorting options (e.g., price, popularity).
page (int): Pagination for large datasets.
Response: JSON object containing product name, ID, price, rating, and description.
/product/{product_id}
Description: Retrieve detailed information for a specific product using its unique ID.
Parameteres:
product_id (string): Unique ID for the product.
Response: JSON object with product details including title, price, features, and customer reviews.
/reviews
Description: Fetch customer reviews and ratings for a specific product.
Parameteres:
product_id (string): Unique ID for the product.
Response: JSON object containing reviewer names, ratings, review texts, and helpfulness votes.
/offers
Description: Retrieve current offers, discounts, and availability for a specific product.
Parameteres:
product_id (string): Unique ID for the product.
Response: JSON object with offer details, including price, discount percentages, and stock availability.
/related
Description: Get recommendations for related products based on a specific product.
Parameteres:
product_id (string): Unique ID for the product.
Response: JSON object containing a list of related product IDs and names.
/categories
Description: Retrieve a list of available product categories on Wayfair.
Response: JSON object containing category names and IDs for filtering products.
/search
Description: Search for products based on various criteria like keywords and filters.
Parameteres:
query (string): Search term to find products.
sort (string): Sorting options (e.g., price, rating).
page (int): Pagination for large datasets.
Response: JSON object with a list of products matching the search criteria.
/price-history
Description: Retrieve historical pricing data for a specific product.
Parameteres:
product_id (string): Unique ID for the product.
Response: JSON object containing price changes over time, including dates and corresponding prices.
API Response Format
All responses are returned in JSON format for easy integration into your application.
from flask import Flask, jsonify, request
app = Flask(__name__)
# Mock data for demonstration
products = {
"1": {
"name": "Wireless Headphones",
"price": 59.99,
"rating": 4.5,
"description": "High-quality wireless headphones with noise cancellation.",
"reviews": [
{"name": "Alice", "rating": 5, "text": "Great sound quality!"},
{"name": "Bob", "rating": 4, "text": "Comfortable and good battery life."}
],
"offers": {"price": 49.99, "discount": 20, "available": True}
},
"2": {
"name": "Bluetooth Speaker",
"price": 29.99,
"rating": 4.0,
"description": "Portable Bluetooth speaker with great sound.",
"reviews": [],
"offers": {"price": 25.99, "discount": 13, "available": True}
}
}
@app.route('/products', methods=['GET'])
def get_products():
keyword = request.args.get('keyword', '')
category = request.args.get('category', '')
sort = request.args.get('sort', 'price')
page = int(request.args.get('page', 1))
# Filtering and sorting logic would go here (mock data only)
return jsonify(products), 200
@app.route('/product/', methods=['GET'])
def get_product(product_id):
product = products.get(product_id)
if not product:
return jsonify({"error": "Product not found"}), 404
return jsonify(product), 200
@app.route('/reviews', methods=['GET'])
def get_reviews():
product_id = request.args.get('product_id')
product = products.get(product_id)
if not product:
return jsonify({"error": "Product not found"}), 404
return jsonify(product['reviews']), 200
@app.route('/offers', methods=['GET'])
def get_offers():
product_id = request.args.get('product_id')
product = products.get(product_id)
if not product:
return jsonify({"error": "Product not found"}), 404
return jsonify(product['offers']), 200
@app.route('/related', methods=['GET'])
def get_related():
product_id = request.args.get('product_id')
# Logic to find related products would go here (mock example)
related_products = {"related": ["3", "4", "5"]}
return jsonify(related_products), 200
@app.route('/categories', methods=['GET'])
def get_categories():
# Mock category data
categories = ["Electronics", "Books", "Home Appliances"]
return jsonify(categories), 200
@app.route('/search', methods=['GET'])
def search_products():
query = request.args.get('query', '')
sort = request.args.get('sort', 'price')
page = int(request.args.get('page', 1))
# Mock response for search (replace with actual search logic)
search_results = {"results": products}
return jsonify(search_results), 200
@app.route('/price-history', methods=['GET'])
def get_price_history():
product_id = request.args.get('product_id')
# Mock price history data
price_history = [
{"date": "2024-01-01", "price": 59.99},
{"date": "2024-02-01", "price": 49.99},
]
return jsonify(price_history), 200
if __name__ == '__main__':
app.run(debug=True)