...

/

Implement GET Endpoint for Getting Details of a Specific Product

Implement GET Endpoint for Getting Details of a Specific Product

Learn how to implement products API using Flask to get the details of a specific Product.

We'll cover the following...

In a REST API, GET can be used to either retrieve the whole collection of resources or a specific item from the collection. In this lesson, we’ll look at how to implement an API that will return a product based on the product ID passed as a path parameter.

Flask provides an easy way to map the path parameter of the URI to the parameter of the method that handles the request for that URI. Without further ado, let’s implement the API endpoint that returns a specific product.

Steps

  1. Open server/api/products_api.py.

  2. Add a new method that accepts a parameter named product_id. Name the method get_product. ...

def get_product(product_id):