Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/michaeltelford/lucky_api_reference_project

A reference project for building JSON API's with Crystal and the Lucky framework
https://github.com/michaeltelford/lucky_api_reference_project

crystal json-api lucky

Last synced: 2 days ago
JSON representation

A reference project for building JSON API's with Crystal and the Lucky framework

Awesome Lists containing this project

README

        

# Lucky API Reference Project

This is a HTTP JSON API written using [Lucky](https://luckyframework.org) and the [Crystal](https://crystal-lang.org/) programming language. It acts as a place of reference to build similar API's that can be consumed by front end applications.

## Rationale

Below are some of the main criteria needed for a stable means of producing JSON API's:

- Blazing performance
- Low memory consumption
- Small final Docker images
- Fast "cold boot" startup times
- Productive development:
- Excellent request validation
- Excellent JSON response serialisation support
- DB ORM & migrations
- Easily tested
- Secure out of the box
- Support for Many-to-Many DB connections e.g. A single API can connect to serveral DB instances and a single DB instance can have several API's connect to it

**Lucky, Crystal and Docker combined tick all of the boxes!**

## Setup

1. [Install required dependencies](https://luckyframework.org/guides/getting-started/installing#install-required-dependencies)
2. Update database settings in `config/database.cr`
3. Run `script/setup`
4. Run `lucky dev` to start the app locally at: `http://127.0.0.1:5000`
5. Use the header `Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.W2mTap2sSGwXHjgUxLy3ruku57djep3yu5ho7ZYS4fQ` for authenticated requests with a sample user during development.

## Docker

Crystal compiles this entire project down to a static binary which is then copied to an Alpine Linux Docker image for production. The image weights in at `~25MB` and starts almost instantly from a cold boot; perfect for deploying to a K8s cluster or to a "scale to zero" cloud platform e.g. Google's Cloud Run. Check out the included Docker tasks and `Dockerfile` for details.

## Learning Lucky

Lucky uses the [Crystal](https://crystal-lang.org) programming language. You can learn about Lucky from the [Lucky Guides](https://luckyframework.org/guides/getting-started/why-lucky).