• Stars
    star
    68
  • Rank 457,643 (Top 10 %)
  • Language
    Crystal
  • License
    GNU Lesser Genera...
  • Created about 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple PostgreSQL REST API in Crystal with devise-like auth.

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

More Repositories

1

kemal-auth-token

Kemal middleware to authentication via HTTP header token using JWT
Crystal
30
star
2

tremolite

Blog generator
Crystal
20
star
3

gpx2exif

A script to geotag your photos using GPX files
Ruby
14
star
4

technical_graph

Simple technical graphs for Ruby
Ruby
10
star
5

ocranizer

Simple CLI organizer
Crystal
7
star
6

akwiatkowski.github.com

Crystal
4
star
7

i_hope_you_die

eWuล›
Ruby
4
star
8

HomeIO

Home control system
Ruby
4
star
9

tremolite_example

Crystal
3
star
10

crystal_gpx

GPX parser in Crystal + some various utils
Crystal
3
star
11

gpx2png

Convert route storen in GPX format to map using Openstreetmap or OSM compatible tileset.
Ruby
3
star
12

ranges_merger

Simple gem for merging various range-like data
Ruby
2
star
13

xmpp_chat_bot

Simple bot for xmpp chat. At the moment it get titles of urls.
Ruby
2
star
14

ruby_city

City simulator
Ruby
2
star
15

ranger

Range object operation in Crystal
Crystal
2
star
16

waypoint_manager

Simple rails app to manage all waypoints, pois, created in (or for) gps device
Ruby
2
star
17

gpx_utils

Basic utils: track import, waypoint list import/export.
Ruby
2
star
18

crystal_api_sample

Sample project using crystal_api shard
Crystal
1
star
19

herealive

JavaScript
1
star
20

pizza_accounting

Simple accounting for office liabilities, for example when buying pizzas.
Ruby
1
star
21

crystal_weather

Weather fetcher in crystal
Crystal
1
star
22

bobik_utils

Various helpful scripts
Ruby
1
star
23

crystal_metar_parser

Parse METAR weather string. METAR standard is used by every major airport.
Crystal
1
star
24

weather_fetcher

Gem for fetching weather from various services
Ruby
1
star
25

meas_receiver

Library for receiving measurements from HomeIO/IoServer
Ruby
1
star
26

homeio_lite

Ruby
1
star
27

homeio_backend

C++
1
star
28

simple_metar_parser

Parsing METARs, simple way.
Ruby
1
star
29

SimplePowerStabilizer

Simple power stabilizer to convert 40-60V to 36V, with RS-485 communication using special AVR uC.
C
1
star
30

koko_rails

Adds Jarzฤ™bina's power to your rails app.
Ruby
1
star
31

webcam_downloader

Download webcams.
Ruby
1
star
32

simple_show_helper

Simple helper for 'show' pages to help lazy developers.
Ruby
1
star