Common Dream

 
Filed under

code

 

Nice Side Effect Of Splitting Out APIs

At work we've been splitting our APIs out of our default controllers in order to keep them more cleanly versioned. It's been kind of a pain, to be honest, but I discovered one really positive side effect the other day. Out of 13 controllers that we had before the refactor, only 4 had anything to do with our API.

And even within those controllers that exposed methods to the API, many methods had nothing to do with the API. So we've now got a much more compact and clearly defined set of controllers that tell us exactly what's going on within our API, and we've got another set that tell us clearly what is going on in our web interface.

Loading mentions Retweet
Filed under  //   code  

Comments [0]

Webbynatra

I do a few development jobs on the side for friends. One such friend got in touch with me about a week ago wanting me to add a form emailer to his static html site (I developed it using Webby). My first thought was to set it up as a Rails app, but that seemed a little overkill for adding a single feature, especially when Webby gives me layouts for static pages and with Rails I'd have to put a solution for that together. Then I thought about using Widget Finger, but I really didn't want to push him to pay for it, especially not when I already had the site hosted on a virtual private server that we have for Hello Theory.

That's when it hit me. I could use Webby to generate an app that was mostly static, but that used Sinatra to handle the form emailer. Starting with my original Webby site, here's how I did it.

First, I added a folder to the project's content folder named public, and moved all of the existing content files into that folder.

 mkdir content/public
 mv content/* content/public 

Next, I added a new Rackup file (config.ru) to the content folder based on these directions.

 require 'rubygems'
 require 'sinatra'
 root_dir = File.dirname(__FILE__)
 set :environment, ENV['RACK_ENV'].to_sym
 set :root, root_dir
 set :app_file, File.join(root_dir, 'simgins.rb')
 disable :run
 run Sinatra::Application 

I set up my Sinatra script to send email using Pony and tested it. There's a great example of using Pony to send email with Sinatra in the Sinatra FAQ.

Finally, I deployed using Webby's deploy feature:

webby deploy

The combination seems to be working like a charm, and keeps things way simpler for static page development than Rails would have. One small issue that I have is that I haven't come up with a good way to touch the tmp/restart.txt file to get Passenger to reload the app each time I deploy, but I've got a few ideas on that.

Loading mentions Retweet
Filed under  //   code  

Comments [0]