antirez / lamernews

Lamer News -- an HN style social news site written in Ruby/Sinatra/Redis/JQuery
http://lamernews.com
Other
1.35k stars 199 forks source link

use Rack for API #142

Open mulderp opened 11 years ago

mulderp commented 11 years ago

Extracting the API into a Rack middleware might be interesting to combine Lamernews with other Rack applications, and/or to build a custom UI variation.

Glad to hear your feedback if this is interesting for you.

The Lamernews API would then be accessible from Rack with:

use Lamernews::API

fcambus commented 11 years ago

While it could be interesting, this breaks the ability to simply install the few required gems manually and launch Lamer News by simply invoking "ruby app.rb", which makes it really easy even for Ruby neophytes to get involved.

Maybe putting the API code in a separate file (could be "api.rb") and simply requiring it from the "app.rb" file could be a good compromise?

mulderp commented 11 years ago

Interesting. I will check.

fcambus commented 11 years ago

I think this is a great idea though, and it should probably be explored!

Also, it could makes things easier to create Lamer News implementations in other languages. As far as I know, there is only one port currently, written in Perl : https://github.com/beanz/camelnews

mulderp commented 11 years ago

When using middlewares, it might make sense to use a middleware to connect to Redis, since that DB layer will be used both in the UI, and in the API part. I updated the PR, it's very experiment. However, both work:

   ruby app.rb
   rackup
huydx commented 11 years ago

hope @antirez will merge this pull request soon. I want to have a clean way to integrate lamernews to my rails app

mulderp commented 11 years ago

Actually, I guess the PR is rather to be closed, since Lamernews and Rails are a bit off different architectures. I would be interested though to hear if this works in principle. I also saw that @mitchellh supports Rack based application architectures: https://github.com/euruko2012/call-for-proposals/pull/83

On Wed, Sep 18, 2013 at 5:41 PM, huydx notifications@github.com wrote:

hope @antirez https://github.com/antirez will merge this pull request soon. I want to have a clean way to integrate lamernews to my rails app

— Reply to this email directly or view it on GitHubhttps://github.com/antirez/lamernews/pull/142#issuecomment-24674757 .

mitchellh commented 11 years ago

@mulderp Vagrant is completely based on "Rack-style" middleware, see here: https://github.com/mitchellh/vagrant/blob/master/plugins/providers/virtualbox/action.rb#L52-L78

mulderp commented 11 years ago

great! thanks for the pointer!

On Wed, Sep 18, 2013 at 6:11 PM, Mitchell Hashimoto < notifications@github.com> wrote:

@mulderp https://github.com/mulderp Vagrant is completely based on "Rack-style" middleware, see here: https://github.com/mitchellh/vagrant/blob/master/plugins/providers/virtualbox/action.rb#L52-L78

— Reply to this email directly or view it on GitHubhttps://github.com/antirez/lamernews/pull/142#issuecomment-24677378 .