runcobo
Runcobo
Runcobo is an api framework in Crystal.
Philosophy
- Simple Design must be simple, both in implementation and interface.
- Intuitive Design must be intuitive.
- Consistent Design must be consistent.
Installation
-
Note: It was in an early version.
-
Add the dependency to your
shard.yml
:
dependencies:
runcobo:
github: runcobo/runcobo
This shard follows Semantic Versioning v2.0.0, so check releases and change the version accordingly.
- Run
shards install
Usage
require "runcobo"
class Api::V1::Add < BaseAction
get "/api/v1/add"
query NamedTuple(a: Int32, b: Int32)
call do
sum = query[:a] + query[:b]
text = "Hello, World! #{query[:a]} + #{query[:b]} = #{sum}"
render_plain text
end
end
Runcobo.start
Api
class BaseAction
# Route
def self.get(url : String)
def self.post(url : String)
def self.put(url : String)
def self.patch(url : String)
def self.delete(url : String)
def self.options(url : String)
def self.head(url : String)
# Params Definition
def self.url(named_tuple : NamedTuple.class)
def self.query(named_tuple : NamedTuple.class)
def self.form(named_tuple : NamedTuple.class)
def self.json(named_tuple : NamedTuple.class)
# Params Call
def url
def query
def form
def json
# Call
def self.call(&block) : HTTP::Server::Context
def self.layout(filename : String)
def self.before(method_name : Crystal::Macros::MacroId)
def self.after(method_name : Crystal::Macros::MacroId)
def self.skip(method_name : Crystal::Macros::MacroId)
# Render View
def render_plain(text : String, *, statu_code :Int32 = 200) : HTTP::Server::Context
def render_body(body : String, *, statu_code : Int32 = 200) : HTTP::Server::Context
def render_jbuilder(filename : String, *, layout : String? = nil, status_code = Int32) : HTTP::Server::Context
end
module Runcobo
# Start
def self.start(*, host : String? = ENV["HOST"]? || "0.0.0.0", port : Int32 = (ENV["PORT"]? || 3000).to_i)
end
Development
WIP
Contributing
- Fork it (https://github.com/runcobo/runcobo/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Write and execute specs (
crystal spec
) and formatting checks (crystal tool format
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Shootingfly - creator and maintainer