crystal-rest-api-template

Version, currently develop branch1 version
  • develop branchlatestJul 14, 2023

github.com/RockManJoe64/crystal-rest-api-template

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

1 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  crystal-rest-api-template:
    github: RockManJoe64/crystal-rest-api-template
    branch: develop

develop is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
1.8.2
License
MIT
Author
Jose Chavez
Target
  • crystal-rest-api-template from src/crystal-rest-api-template.cr

Dependencies

Runtime Dependencies

  • pg0.23.2github: will/crystal-pg
  • grip*github: grip-framework/grip
  • clear*github: anykeyh/clear, branch: master
  • dotenv*github: drum445/dotenv
  • micrate*github: juanedi/micrate
  • hardwire*github: rwnx/hardwire

README

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