Project

ruby_base

0.0
No release in over 3 years
Low commit activity in last 3 years
A fast and hackable JSON API engine based on EventMachine to be used as a backend for Angular, ember and all sorts of things. It is REALLY fast and have a DSL like sinatra, also have an embebed cache system
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

RubyBase

A fast and hackable JSON API engine based on EventMachine to be used as a backend for Angular, Ember , Etc...

Highlights

  • Fast. Like, Reaally fast.
  • Simple
  • Few moving parts, just 100 lines of code.
  • Hackable
  • Cache system embbebed.
  • Sinatra-like DSL
  • Regexps all the way.
  • Production ready (no configuration needed)
  • Pure ruby (dependencies have native extensions)

Installation

Just run the default

sudo gem install ruby_base

Or add

gem "ruby_base"

to your gemfile

Usage

require 'ruby_base'

# reopen the Router class
class RubyBase::Router
  get '/hello' do
    "Hello world!"
  end
  # returns
  # 127.0.0.1/hello
  #=> "Hello world!"
end

RubyBase.run

Always remember to call RubyBase.run when you finish declaring the system behavior.
What you return in the block is automatically parsed to JSON and sent to the client

Usage #2: POST data

class RubyBase::Router
  post '/hello' do |r|
    puts r[:post]
  end
end

RubyBase.run

r[:post] is the post data sent by the client already parsed from JSON

Usage #3: Dinamic Urls

class RubyBase::Router
  get '/hello/([^/]+)' do |r|
    "Hello world!" * (r[:match][1]).to_i
  end
  # returns
  # 127.0.0.1/hello/2
  #=> "Hello world! Hello world!"
end

RubyBase.run

RubyBase Matching system

RubyBase reads your routes from top to bottom and tries to match all of them until some route matches the route requested by the client.
That r[:match] is the MatchData generated from the matching.

RubyBase Cache system

When a 'GET' request is fulfilled and processed it is saved on cache.
The next time that the client request that exact route in the exact method it will automatically receieve the cached response.

If a request with a method different from GET (POST,PUT,PATCH,DELETE) is made ALL CACHE IS DELETED and all the caching starts again.

If you want, you can disable the cache system entirely by adding this

class RubyBase::Router
  @@cache = false
end

Hacking RubyBase

  • Read the code
  • Re-Open desired classes as you did with RubyBase::Router
  • Implement/Change desired behavior
  • Profit!

Contributing

RubyBase is a small and simple thing.
And i have no plans in making it the NEW SOLUTION FOR ALL THINGS TM.
RubyBase tries to solve one problem and tries to do it well. Don't try to bloat it with new "maybe usefull" features.

That said i think that RubyBase needs an Authorization system in order to have some Sessions Right now i have little free time to do it so if you want to help try implementing that.
Just send pull requests commenting what you have done.

Issues and known problems

If you have a problem pull a issue in this repo commenting what is going wrong.
Check this list first so you don't report an already known problem.

Known problems:

  • No way of modifying response HTTP Header (IE 404 errors can't be made)
  • No session system.
  • No Auth system.