Ruby and Rack based api for meal planner application.
This is a pet project that will serve as a smaller piece to a larger meal planning application which demonstrates the use of Sinatra as a Rack based micro service. The service uses Active Record and Postgres for data persistence, but does not have much of the "Rails magic," at least not setup by default. See below for the api documentation.
To run locally,
bundle install
bundle exec puma --config config/puma.rb
You can test that the server is working by hitting the health endpoint,
curl -D - -X GET --url http://localhost:4000/healthz
If you want to use Docker to setup a Postgres database locally, you can do so via Rake task,
bundle exec rake docker:db:start
This will start a Postgres database using env variables for the hosted port, database name, username and password. To tear this db down, run
bundle exec rake docker:db:stop
Environment variables used for configuration,
Var | Default | Setting |
---|---|---|
MEAL_PLANNER_API_DB_HOST | localhost | Tcp address of the database |
MEAL_PLANNER_API_DB_PORT | 15400 | Tcp port of the database |
MEAL_PLANNER_API_DB_USERNAME | - | Postgres username |
MEAL_PLANNER_API_DB_PASSWORD | - | Postgres password |
DATABASE_URL | - | Postgres url (with username, password, host and port) - overwrites all above |
SINATRA_ENV | development | Environment to run in |
RACK_ENV | - | Environment to run Rack server in |
PORT | 4000 | Port to host Rack server on |
RUN_COVERAGE | Set to "true" to get SimpleCov coverage report |
There is a Dockerfile for this project. To build it,
docker build --tag meal-planner-api .
Then to run via container,
docker run --rm --detatch --port 4000:4000 --name meal-planner-api meal-planner-api:latest
To set configuration options, use the docker run
--env
option to pass in environment variables
as in the above configuration section.
WIP - to come. This section will contain api docs for available HTTP routes.
Tests are written using the MiniTest framework. To run tests,
bundle exec rake test
Linting is done by Rubocop and can be run with,
bundle exec rubocop -D