Skip to content

Foodie-DAAM/foodie-api

Repository files navigation

Foodie

Foodie API

Links

Verb Endpoint Description
GET /recipes Get all recipes, paged.
GET /recipes/{id} Get recipe with ID.
GET /recipes/digest Run batch job to populate database with test data.

Setting up the database

Install the MongoDB Community Server, and run the following commands in the mongo shell (mongo --port 27017) to configure the admin users. After that is done, you may use mongo --port 27017 --authenticationDatabase foodie -u foodie -p to connect to the database.

use admin
db.createUser({
	user: "admin",
	pwd: "admin",
	roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
});

use foodie
db.createUser({
	user: 'foodie',
	pwd: 'foodie',
	roles: [ 'readWrite' ]
});
db.adminCommand({ shutdown: 1 });

Run the following commands if you wish to dumping and restore the collection data:

  • mongodump --host localhost --port 27017 --db foodie --collection recipe
  • mongorestore --host host --port 27017 -u user -p pass dump

Foodie Loader

Loads scrapped recipes into a database.

How to use: start the API service, then call the endpoint at http://localhost:10000/recipes/digest.

Foodie Scraper

Scrapes recipes from https://allrecipes.com.

Prerequisites

  • Have Python 3 installed
  • pip install beautifulsoup4 recipe-scrapers

Run

  • python get_recipes.py --pages 5000 --sleep 5 --status 1
  • python get_pictures.py --filename "recipes_raw.json"

Docker

Setting up dev environment:

  • docker-compose -p foodie up -d db
  • docker-compose -p foodie up -d api

Building and pushing a new API image:

  • gradlew bootJar
  • docker-compose build
  • docker image tag foodie:latest sandrohc/foodie:latest
  • docker push sandrohc/foodie:latest

Building and testing a local image:

  • docker build -t foodie .
  • docker run -it --rm foodie