Skip to content

GET /foods — Retrieve All Foods

Returns a paginated list of foods from the database. By default, it retrieves the first 100 food items, but supports filters and pagination through query parameters.

Example Request

GET /foods

Example Response

json
{
  "data": [
    {
      "id": 1,
      "name": "Plain Yogurt",
      "brand": "Chobani",
      "ingredients": ["Milk", "Cultures"]
    }
  ],
  "page": 1,
  "total": 1
}

Query Parameters

ParameterTypeDescriptionExample
categorystringFilter results by food category/foods?category=poultry
brandstringFilter by brand name/foods?brand=Nestle
pageintegerSpecify which page of results to retrieve/foods?page=2
limitintegerSet how many items to return per page (default: 100)/foods?limit=50

Pagination Example

For a live demonstration of how pagination is handled in the front end, visit the Pagination Example Page.

This example page shows:

  • How results are loaded and displayed across multiple pages
  • How query parameters (page and limit) affect the data returned
  • How to handle “next” and “previous” page navigation in a UI context

Typical Errors

StatusMeaningExample
200 OKSuccessfully retrieved list of foods
400 Bad RequestInvalid query parameter/foods?page=abc
404 Not FoundNo foods matched the query/foods?brand=Unknown
500 Internal Server ErrorUnexpected server issue

Example Error Response:

json
{
  "error": "Invalid query parameters"
}