Sinatra routes documentation is too short:
options '/' do
.. appease something ..
end
link '/' do
.. affiliate something ..
end
unlink '/' do
.. separate something ..
end
I've been searching for REST docs and HTTP methods. I've found some words for options
here and for link
here (section 19.6.2.4) and the <link> html tag, and an example of link
use in Riak database to emulate a graph db.
But I'm searching for Sinatra use cases and examples. I need to know if I don't need them or if I'm missing something important in these RESTful days before to start a new project.
OPTIONS, LINK, and UNLINK are all standard HTTP 1.1 request methods. These are somewhat obscure methods when compared to the much more used methods like GET and POST. There is nothing Sinatra specific about these. In general Sinatra offers ruby methods with the same name as HTTP methods. How we respond to the method is pretty much left to us. An example implementation of the OPTIONS method would look like -
options '/subscriptions' do
status 200
headers "Allow" => "BREW, POST, GET, PROPFIND, WHEN"
end
All this is doing is telling Sinatra that when the web server receives an HTTP request that looks like -
OPTIONS /subscriptions HTTP/1.1
Host: www.yourwebsite.com
It should respond as follows
HTTP/1.1 200 OK
Allow: BREW,POST,GET,PROPFIND,WHEN
If your app has a need to link or unlink two resources then go ahead and use these methods. There is nothing inherently RESTful or unRESTful about them. OPTIONS is more like a "reflection" method for a resource. If you are implementing a client, then it would be a good idea to have some fallback in case the server does not implement these methods properly.