Posts Tagged ‘content negotiation’
Restfulie 0.5.0 is out and its major new feature is its support to Atom feeds with variable media types.
A feed can be easily rendered by invoking the to_atom method:
@hotels = Hotel.all
render :content_type => 'application/atom+xml',
:text => @hotels.to_atom(:title=>'Hotels', :controller => self)
A collection might contain entries with different media types and each one will be rendered in its own way. The client code works as any other usual client would, note that there is still content negotiation taking place:
hotels = Restfulie.at('http://localhost:3000/hotels').get
And using hypermedia to drive our business, deleting an entry will send a DELETE request to that entry’s self URI:
Restfulie.at('http://localhost:3000/hotels').get.each do |h|
h.delete if h.city=="Sao Paulo"
In future releases we expect to support atom feed generation (and consuming) through Ratom.
Another easy to use feature is content type negotiation, which also happens when rendering a single resource:
@hotel = Hotel.find(params[:id])
Users can now extend Restfulie in order to create custom formats (not based on json/xml/xhtml related media types)
Entry points have been extended and now they can be reached even if there is no class representing the received information in the client side:
One can also access the web response:
response = Restfulie.at('http://localhost:3000/cities/5').get.web_response
And play with content negotiation:
In the server side, a generic controller has been created which supports show, delete and create by default.
There is also a new method called render_created that can be used in order to answer a request with a 201 Created response and its resource location.
Restfulie got its own website and all Ruby docs have been migrated.
Thanks to all the team and collaborators!
If you look carefully, you might find out next week’s upcoming news.