How to get a collection of products
The Brew Ha Ha API includes an endpoint that allows client applications to GET
a collection of resources.
In this guide, you’ll make a GET
request to the /products/
endpoint to get a list of all products in the database.
Before you begin
Before you make a GET
request, ensure that you have an access token. For instructions on requesting an access token, see Request a JSON Web Token.
Make a GET request
-
Open a terminal and run the following command:
get_request_collection.sh curl -H "Authorization: Bearer <your_token>" http://127.0.0.1:8000/api/products/The API returns a
200 OK
and list of products in the database:get_request_collection_response.sh "results": [{"id": 1,"product_name": "mocha","temperature": "hot","caffeine_amount": 105,"price": 3.75,"description": "A rich, decadent blend of espresso and chocolate","quantity": 3},{"id": 2,"product_name": "blueberry muffin","temperature": null,"caffeine_amount": null,"price": 2.5,"description": "A fluffy, warm blueberry muffin","quantity": 10},{"id": 3,"product_name": "cortado","temperature": "hot","caffeine_amount": 130,"price": 4.0,"description": "Made with beans picked from the coast of Spain","quantity": 5}]
You can use the data from the GET
request in your application. For example, you could display information about each product on a product detail page.
What to do next
See GET /products/ for a full list of request parameters and response schemas.