runcobo

An api framework with simple, intuitive and consistent DSL, using jbuilder to render json webframework microservice api
2.0.0 Latest release released
runcobo/runcobo
50 1
runcobo

Runcobo

Travis CI build Built with Crystal Latest release API docs

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

  1. 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.

  1. Run shards install

Usage

require "runcobo"

class Api::V1::Add < BaseAction
  get "/api/v1/add"
  query NamedTuple(a: Int32, b: Int32)

  call do
    sum = params[:a] + params[:b]
    render_plain sum.to_s
  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)
  def self.route(method : String, url : String)

  # Params Definition
  macro url(named_tuple : NamedTuple.class)
  macro query(named_tuple : NamedTuple.class)
  macro form(named_tuple : NamedTuple.class)
  macro json(named_tuple : NamedTuple.class)

  # Params Call
  def params : NamedTuple

  # Call
  macro call(&block) : HTTP::Server::Context
  macro layout(filename : String)
  macro before(method_name : Crystal::Macros::MacroId)
  macro after(method_name : Crystal::Macros::MacroId)
  macro 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
  macro render_water(filename : String, *, layout = "", status_code = Int32, dir = "src/views/", layout_dir = "src/views/layouts/") : HTTP::Server::Context
  macro render_jbuilder(filename : String, *, layout = "", status_code = Int32, dir = "src/views/", layout_dir = "src/views/layouts/") : HTTP::Server::Context
end

module Runcobo
  # Start Server
  def self.start(*,
                 host : String = ENV["HOST"]? || "0.0.0.0",
                 port : Int32 = (ENV["PORT"]? || 3000).to_i,
                 reuse_port : Bool = false,
                 handlers : Array(HTTP::Handler) = Runcobo::Server.default_handlers,
                 cert : String? = ENV["CERT"]?,
                 key : String? = ENV["KEY"]?)
end

Contributing

  1. Fork it (https://github.com/runcobo/runcobo/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write and execute specs (crystal spec) and formatting checks (crystal tool format)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Contributors

runcobo:
  github: runcobo/runcobo
  version: ~> 2.0.0
License MIT
Crystal 1.0.0

Authors

  • Shootingfly

Dependencies 3

  • jbuilder
    {'github' => 'shootingfly/jbuilder'}
  • radix
    {'github' => 'luislavena/radix'}
  • water
    {'github' => 'shootingfly/water'}

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently