kemal-rest-api

A library to create RESTful API with Kemal kemal rest api
0.1.0 released

kemal-rest-api Build Status

A Crystal library to create REST API with Kemal.

NOTE: this is an alpha 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"

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

KemalRestApi::Resource.new MyModel.new, nil, singular: "item"

module WebApp
  KemalRestApi.generate_routes!
  Kemal.run
end

## Generated routes:
# POST /items
# GET /items/:id
# PUT /items/:id
# DELETE /items/:id
# GET /items

KemalRestApi::Resource options

  • singular: singular name of the model
  • plural: plural name of the model

More examples

See examples folder.

Notes

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

Contributors

kemal-rest-api:
  github: blocknotes/kemal-rest-api
  version: ~> 0.1.0
License MIT
Crystal 0.20.4

Authors

Dependencies 1

  • kemal
    {'github' => 'kemalcr/kemal'}

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently