Skip to content

Latest commit

 

History

History
105 lines (77 loc) · 4.09 KB

README.md

File metadata and controls

105 lines (77 loc) · 4.09 KB

crystal_api

Dependency Status devDependency Status Build Status

crystal_api is a set of tools to allow create very fast JSON APIs.

Key notes:

  • all models are struct instead of class (like in active_record.cr)
  • custom SQL requests are preferred and encouraged
  • but you can use one macro to create all REST (no customization)
  • there are some Rails-like methods (coming soon)
  • logic need to be customized

Sample payment API is explained here

Here, Alive - real life API example with JS frontend

API of API - list of all methods (coming soon)

Roadmap

  • Fix DB mapping to allow create database - add types of columns to definition list
  • Check and fix JSON mapping
  • Update action
  • Destroy action
  • Clean Postgres adapter
  • Rewrite for easier usage as lib
  • JSON response header
  • DB inline config (no config file needed)
  • devise compatible sign in controller
  • JWT request authentication
  • Initial rights managament
  • Utilize singleton-like approach to get service
  • Remove kemal-pg and use crystal-pg
  • Use DB connection pool
  • Use typed queries
  • Escape parameters - only quotation characters
  • Add Nil to field type as union by default - shorter model definition
  • Rename service to something better
  • Add "scope" method to model Mode.scope({where: Hash, limit: Int32, order: String})
  • Add page, per_page, offset
  • Add random to fetch_one
  • Add random order to fetch_all
  • One method for fetching
  • Models should be as much immutable as possible
  • Websockets

Usage

Please check:

Fast full REST

pg_connect_from_yaml("config/database.yml")

# all fields must be union with Nil
crystal_model(EventModel, id : Int32, name : String)

# magic macro
# crystal_resource_full_rest(<name>, <resource path without '/' >, <DB table name>, <Model struct>)
crystal_resource_full_rest(event, events, events, EventModel)

# create table if not exists
crystal_migrate_event

# set port
Kemal.config.port = 8002
# run, this run migrations before running the HTTP server
CrystalInit.start

Custom API

Please check short sample. This is money transfers API. User has its account and assigned payments: incoming (external transfered money to system), outgoing (user withdraw money), transfer (user's account money transfered to another user's account).

Rails like model methods

At this moment I'm refactoring and adding code for easier DB operations. Readme will be updated after that moment.

Contributing

  1. Fork it ( https://github.com/akwiatkowski/crystal_api/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