Skip to content

A full-featured, production ready, and easy to understand API boilerplate for the Grape framework.

License

Notifications You must be signed in to change notification settings

codebunnies/api-boilerplate

This branch is up to date with duffn/grape-api-boilerplate:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

483f685 · Jan 27, 2025
Jan 27, 2025
May 5, 2024
May 5, 2024
May 5, 2024
May 5, 2024
Jun 20, 2022
May 5, 2024
Jun 20, 2022
Jun 20, 2022
Jun 21, 2022
Jun 12, 2024
Jan 27, 2025
Jun 20, 2022
Jan 27, 2025
Jan 27, 2025
Jan 27, 2025
Jun 20, 2022
Jun 20, 2022
Jun 20, 2022
Jan 27, 2025
May 5, 2024
May 5, 2024
Jan 27, 2025
Jun 21, 2022

Repository files navigation

grape-api-boilerplate

Tests Rubocop codecov

A full-featured, production ready, and easy to understand API boilerplate for the Grape framework.

Features

Running

  • Generate a key pair for local JWT authentication.
cd grape-api-boilerplate/config/jwt
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
  • Build and run with Docker Compose.
docker compose up --build
  • Setup and seed the database.
docker compose exec app bundle exec rake db:setup

Creating a user

  • Run the create users Rake task.
docker compose run --rm app bundle exec rake users:create
  • Enter your desired email, username, and password.

Authentication and requests

  • Hello world.
curl http://localhost:3000/api/v1/hello | jq .
  • Authenticate and authenticated request.
# Authenticate with the test user.
token=$(curl -XPOST \
  -H "Content-Type:application/json" \
  -d '{"username":"grape_user","password":"grape_user1"}' \
  http://localhost:3000/api/login | jq -r '.token')

curl -H "Authorization: Bearer ${token}" \
  http://localhost:3000/api/v1/widget | jq .

Tests

  • Run linting and tests.
docker compose run --rm -e RACK_ENV=test app bundle exec rake

API documentation

When running locally, you can visit http://localhost:3000/public/swagger/index.html to view your Swagger API documentation.

Production

Sentry

You can enable Sentry for your API by setting sentry.enabled in your settings file(s).

  • Update the setting in app/settings/<environment>.yml.
sentry:
  enabled: true
  • Add your Sentry DSN to a SENTRY_DSN environment variable.

  • See the Sentry Rack guide for more.

Prometheus

You can enable Prometheus metrics for your API by setting prometheus.enabled in your production settings file.

  • Update the setting in app/settings/production.yml.
prometheus:
  enabled: true

Note: Prometheus metrics should not be exposed publicly! Please ensure you know what you're doing before enabling this feature in your environment.

Docker

Build a production ready image with the Dockerfile and deploy to your favorite platform.

docker build -t grape-api-boilerplate:latest .

Contributing

Contributions are welcome! See CONTRIBUTING.

License

MIT License. See LICENSE for details.

About

A full-featured, production ready, and easy to understand API boilerplate for the Grape framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 83.2%
  • HTML 10.9%
  • Dockerfile 3.3%
  • JavaScript 1.7%
  • Other 0.9%