Building A RESTful API in Rails 3

I just put together a short screencast showing how simple it is to build a RESTful API using Rails 3.

The screencast also shows how the default scaffold templates can be refactored to be DRYer.

You can pull a copy of the application code (with further refactoring advice) from it's repository on GitHub

Feedback and replies welcome

Comments

This is why I love Rails!

Great presentation by the way - well done

Posted on by Gary Diamond

Hi,

Thanks for the screencast. This is not exactly a REST API, it's a CRUD interface that spits JSON.

An API is RESTful if it satisfies the hypermedia constraint. You can look up HATEOAS for more information.

Posted on by ZingZong

@ZingZong - thanks for your comment!

You're right that this screencast is only showing how to build a CRUD app that spits out JSON. I initially put the video together to show a client who's planning to build a REST API for their web service that Ruby on Rails was a good way to go.

The screencast was really to show off Rails as a tool than a step-by-step to building a REST API. I hadn't thought when posting it to the blog that this context would be lost though.

Your comment prompted me to do more research on REST and HATEOAS though. This post and the comments discussion below are a great read.

From what I (now) understand about HATEOAS, building a truly RESTful API using the JSON MIME-type would involve also responding with the URLs for permitted actions too... which in most cases I would argue is pedantic.


I love your accent - lol

Posted on by Jan Meyers

Why not leave me a comment?


(never displayed)