crystal_api
is a set of tools to allow create very fast JSON APIs.
Key notes:
- all models are
struct
instead ofclass
(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)
- 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 usecrystal-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
tofetch_one
- Add
random
order tofetch_all
- One method for fetching
- Models should be as much immutable as possible
- Websockets
Please check:
- Tests,
- Sample payment API explained,
- Here, Alive - real life API example with JS frontend,
- API of API - list of all methods is coming soon
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
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).
At this moment I'm refactoring and adding code for easier DB operations. Readme will be updated after that moment.
- Fork it ( https://github.com/akwiatkowski/crystal_api/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- akwiatkowski Aleksander Kwiatkowski - creator, maintainer