Avahi/Zeroconf or Rendezvous as your Mac would know it, can be used in published DNS records (unicast) as well as the normal LAN type setup (multicast), its already a standard why don’t we use this for discovering RESTful resources?
All this would require would be a service type registered eg. rest.tcp and a flag in the TXT record naming your resources eg. “resources=/users /articles /articles/comments”.
I brought this up (quite randomly) during a talk at my local Ruby Group (ncl.rb).
Gimme your feedback?
UPDATE Forgot to add from the initial post use the :resource/new to get an empty object (to_xml or whatever)
An example of discovering unicast Zeroconf services isshift@carbon:~# avahi-browse -a -d 0pointer.de + n/a n/a Lennart’s Blog _http-rss._tcp 0pointer.de + n/a n/a tango SSH Remote Terminal 0pointer.de + n/a n/a dt115 SSH Remote Terminal 0pointer.de + n/a n/a ring2 SSH Remote Terminal 0pointer.de + n/a n/a PulseAudio Web Site Web Site 0pointer.de + n/a n/a Avahi Web Site Web Site 0pointer.de + n/a n/a Lennart's Blog Web Site 0pointer.de + n/a n/a Lennart's Photos Web Site 0pointer.de + n/a n/a Lennart's Homepage Web Site 0pointer.de
This isn’t so much a blog post as somewhere convenient to put some information for ncl.rb.
My Apache 2.2 + modproxybalancer virtualhost config
<VirtualHost *:80>
ServerName yourapp.com
DocumentRoot /home/web/yourapp.com/current/public/
<Directory "/home/web/yourapp.com/current/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
# Configure the cluster member proxy
<Proxy balancer://your_app_cluster>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
BalancerMember http://127.0.0.1:3003
</Proxy>
RewriteEngine On
# If there is a maintenence.html file in your
# public dir all requests will get rerouted to
# this file. This is for use with capistrano
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [L]
# Rewrite index to check for static index.html
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached pages with .html extentions
RewriteRule ^([^.]+)$ $1.html [QSA]
# All dynamic requests get sent to the cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://your_app_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate for clients that support it.
AddOutputFilterByType DEFLATE text/html text/plain text/xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Error and access logs.
ErrorLog /var/log/apache/app_error.log
CustomLog /var/log/apache/app_access.log combined
</VirtualHost>
Now if you take the above example it’ll send all requests to your pack of mongrels, but say you want to have more then one application running on your domain (say beast).
You’ll need to create another proxy balancer
<Proxy balancer://your_second_app_cluster>
BalancerMember http://127.0.0.1:3004
BalancerMember http://127.0.0.1:3005
BalancerMember http://127.0.0.1:3006
BalancerMember http://127.0.0.1:3007
</Proxy>
And then add the RewriteRule for it
RewriteRule ^/forums/(.*)$ balancer://your_second_app_cluster%{REQUEST_URI} [P,QSA,L]
Now anything going to / that isn’t /forums/.* will goto yourappcluster and anything with /forums/.* will goto yoursecondapp_cluster
<VirtualHost *:80>
ServerName yourapp.com
DocumentRoot /home/web/yourapp.com/current/public/
<Directory "/home/web/yourapp.com/current/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
# Configure the cluster member proxy
<Proxy balancer://your_app_cluster>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
BalancerMember http://127.0.0.1:3003
</Proxy>
<Proxy balancer://your_second_app_cluster>
BalancerMember http://127.0.0.1:3004
BalancerMember http://127.0.0.1:3005
BalancerMember http://127.0.0.1:3006
BalancerMember http://127.0.0.1:3007
</Proxy>
RewriteEngine On
# If there is a maintenence.html file in your
# public dir all requests will get rerouted to
# this file. This is for use with capistrano
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [L]
# Rewrite index to check for static index.html
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached pages with .html extentions
RewriteRule ^([^.]+)$ $1.html [QSA]
# All dynamic requests get sent to the cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/forums/(.*)$ balancer://your_second_app_cluster%{REQUEST_URI} [P,QSA,L]
RewriteRule ^/(.*)$ balancer://your_app_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate for clients that support it.
AddOutputFilterByType DEFLATE text/html text/plain text/xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Error and access logs.
ErrorLog /var/log/apache/app_error.log
CustomLog /var/log/apache/app_access.log combined
</VirtualHost>
yourappcluster mongrel_cluster.yml
--- port: "3000" environment: production address: 127.0.0.1 pid_file: log/mongrel.pid servers: 4 yoursecondappcluster mongrelcluster.yml --- port: "3004" environment: production address: 127.0.0.1 pid_file: log/mongrel.pid servers: 4
Hope that made sense, as its off the top of the head apart from the base apache 2.2 vhost config
UPDATE If your running a Rails app under a path remember to set
ActionController::AbstractRequest.relative_url_root = '/path'
In your environment.rb or your links will be wrong
Vincent is a self-confessed geek, who's day job is as a Rails developer, outside of work he likes to play with home automation gadgets. He resides in Newcastle upon Tyne.