All Projects → blocknotes → kemal-rest-api

blocknotes / kemal-rest-api

Licence: MIT license
Crystal library to create REST API with Kemal

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to kemal-rest-api

kemal-vue-chat
this is experimental repo for Kemal and Vue.js (+ WebSocket)
Stars: ✭ 32 (-42.86%)
Mutual labels:  kemal
spec-kemal
Easy testing for Kemal
Stars: ✭ 51 (-8.93%)
Mutual labels:  kemal
Kemal
Fast, Effective, Simple Web Framework
Stars: ✭ 3,227 (+5662.5%)
Mutual labels:  kemal
kemal-session
Simple session handler for Kemal
Stars: ✭ 47 (-16.07%)
Mutual labels:  kemal
crystular
Crystal regex tester http://www.crystular.org/
Stars: ✭ 31 (-44.64%)
Mutual labels:  kemal
kemal-basic-auth
Basic auth for your Kemal application
Stars: ✭ 14 (-75%)
Mutual labels:  kemal
kemal-watcher
Kemal plugin to watch files and live-reload the browser
Stars: ✭ 21 (-62.5%)
Mutual labels:  kemal
kave
Kemal API Version Extension
Stars: ✭ 31 (-44.64%)
Mutual labels:  kemal

kemal-rest-api Build Status

A Crystal library to create REST API with Kemal.

See examples folder for mysql, sqlite3 and mongo samples.

NOTE: this is a beta version, a lot of features and security improvements need to be implemented actually

Installation

Add this to your application's shard.yml:

dependencies:
  kemal-rest-api:
    github: blocknotes/kemal-rest-api

Usage

require "db"       # dependency required to use CrystalDbModel
require "sqlite3"  # dependency required to use CrystalDbModel - alternatives: crystal-mysql, crystal-pg
require "kemal"
require "kemal-rest-api"

class MyModel < KemalRestApi::Adapters::CrystalDbModel
  def initialize
    super "sqlite3:./db.sqlite3", "my_table"
  end
end

module WebApp
  res = KemalRestApi::Resource.new MyModel.new, KemalRestApi::ALL_ACTIONS, prefix: "api", singular: "item"
  res.generate_routes!
  Kemal.run
end

Generated routes:

GET    /api/items
GET    /api/items/:id
POST   /api/items
PUT    /api/items/:id
DELETE /api/items/:id

KemalRestApi::Resource options

  • json (Bool): form payload as JSON instead of formdata, default = true
  • plural (String): plural name of the model, used for routes, default = singular pluralized
  • prefix (String): prefix for all API routes, default = ""
  • singular (String): singular name of the model, default = class model name lowercase

More examples

See examples folder.

Notes

crystal-db shard is required only if KemalRestApi::Adapters::CrystalDbModel is used.

The proposed adapters are basic implementations, you can create easily a model adapter that responds better to your needs. prepare_params is used to adjust the create/update parameters.

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].