runcobo

An api framework with simple, intuitive and consistent DSL, using jbuilder to render json webframework microservice api
0.1.0 released
runcobo/runcobo
49 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. Note: It was in an early version.

  2. 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 = 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

  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: ~> 0.1.0
License MIT
Crystal 0.34.0

Authors

  • Shootingfly

Dependencies 3

  • jbuilder
    {'github' => 'shootingfly/jbuilder'}
  • radix
    {'github' => 'luislavena/radix'}
  • teeplate ~> 0.8.0
    {'github' => 'mosop/teeplate', 'version' => '~> 0.8.0'}

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently