lamernews icon indicating copy to clipboard operation
lamernews copied to clipboard

use Rack for API

Open mulderp opened this issue 11 years ago • 8 comments

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

mulderp avatar Jul 17 '13 10:07 mulderp

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?

fcambus avatar Aug 11 '13 21:08 fcambus

Interesting. I will check.

mulderp avatar Aug 12 '13 06:08 mulderp

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

fcambus avatar Aug 12 '13 13:08 fcambus

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

mulderp avatar Aug 14 '13 20:08 mulderp

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

huydx avatar Sep 18 '13 15:09 huydx

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 [email protected] 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 .

mulderp avatar Sep 18 '13 16:09 mulderp

@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

mitchellh avatar Sep 18 '13 16:09 mitchellh

great! thanks for the pointer!

On Wed, Sep 18, 2013 at 6:11 PM, Mitchell Hashimoto < [email protected]> 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 .

mulderp avatar Sep 18 '13 16:09 mulderp