lucky_api_reference_project

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

Lucky API Reference Project

This is a HTTP JSON API written using Lucky and the Crystal 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
  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 programming language. You can learn about Lucky from the Lucky Guides.

Repository

lucky_api_reference_project

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 5
  • over 3 years ago
  • November 8, 2020
License

Links
Synced at

Thu, 02 May 2024 01:29:49 GMT

Languages