Simple REST API application for getting food nutrition value.
Setup the SQLite database, run the server locally and access it at localhost:8000
:
python db_setup.py
uvicorn app.main:app --reload
Or run the server in a Docker container and access it at localhost
:
docker run -d -p 80:80 myimage
Unit and integration tests can be run with pytest:
pytest
GET /nutrition/{food_name}
POST /nutrition
Request body must contain name, serving size (in grams, optional) and calories per 100 grams in the following format:
name: str
serving_size: Optional[float] = 100
calories_per_100_g: float
Get information about food weight and calories given calories amount, weight or a number of servings.
GET /nutrition/{food_name}/calories?calories=...
GET /nutrition/{food_name}/weight?weight=...
GET /nutrition/{food_name}/servings?servings=...
Get information about food weight and calories given a list of food items with weight and calories. Information about each item can be obtained using the previous request.
GET /compound-nutrition
Request body must contain a list of item in the following format:
name: str
weight: float
calories: float
Get either all available recipes or some recipe by its name. Access GraphiQL at /recipes
and enter your query.
type Nutrition {
calories: Float
fats: Float
carbs: Float
protein: Float
}
type Ingredient {
name: String
amount: Float
nutrition: Nutrition
}
type Recipe {
name: String
ingredients: [Ingredient]
steps: [String]
nutrition: Nutrition
}
type Query {
recipes(name: String): [Recipe]
}
query {
recipes {
name
steps
ingredients {
amount
name
}
}
}
query {
recipes(name: "Avocado Toast") {
name
ingredients {
name
nutrition {
calories
fats
protein
carbs
}
amount
}
nutrition {
calories
carbs
fats
protein
}
steps
}
}