OpenFoodBase is a free and open source database which contains nutritional facts on food. The live database can be found here.
Creating and searching food in the database can be done with a set of API calls.
Detailed information about the different API calls can be found here. Please use this API calls with respect to the OpenFoodBase project and to other users! Please do not insert wrong informartion! If you made a mistake, please contact me!
Here are a few example calls:
(by default the number of food items is limited to 20)
Perform a GET request to:
https://openfoodbase.herokuapp.com/search/food/all
this leads to the following result (truncated):
[
{
"_id": "5c25006c21e4dfd83dc151c3",
"name": "Apple",
"serving": "100g",
"calories": 54,
"protein": 0.3,
"carbs": 14.3,
"fat": 0.1,
"barcode": 123123123,
"image": "putyourimageurlhere",
"__v": 0
},
Perform a POST request with the body:
{
"name": "Apple",
"serving": "100g",
"calories": 54,
"protein": 0.3,
"carbs": 14.3,
"fat": 0.1
}
to:
https://openfoodbase.herokuapp.com/create/food
If you wish to run the API on your local machine, use the following instructions.
Make sure to have Node installed on your system and navigate to the src
directory.
cd src
run:
npm install
to start the Node server:
npm run dev
Congratulations, you are now running OpenFoodBase on localhost:3000
! Enjoy 🎉
Please feel free to adapt it to your needs. I would be very grateful to include your inprovements. Thanks for your support!