crystal-rest-api-template

A template implementing best practices to create a REST API in Crystal lang!

crystal-rest-api-template

This repo defines a standard of creating a REST API that interfaces with a relational database.

  • It's using the grip-framework to wire up the RESTful endpoints.
  • Clear is being used as the ORM. This means PostgreSQL is the target database.
  • Micrate handles database migrations against a Postgres DB.
  • Your .env file will be loaded via dotenv.
  • Hardwire handles the dependency injection!

Installation

Make sure you have crystal installed on your Linux/MacOS/WSL environment.

Install the shards.

shards install

Create a .env file with the DB connection URL. You can copy the sample.env file for this. Modify the docker-compose.yaml file with details on your database, or keep it as is.

Usage

Bring up the Postgres DB using docker-compose.

docker-compose up

Run migrations against your DB.

./migrations/micrate up

Run the application.

crystal src/main.cr

Test it via a curl command.

curl "http://0.0.0.0:8080/"

Development

Use this template to quickly create a REST microservice.

It's crystal. Have fun!

Contributing

  1. Fork it (https://github.com/your-github-user/crystal-rest-api-template/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

crystal-rest-api-template

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 5
  • over 1 year ago
  • July 9, 2023
License

MIT License

Links
Synced at

Sun, 17 Nov 2024 06:34:45 GMT

Languages