A New World of Resources

Mon May 23 22:04:00 -0700 2011

Last year I attacked a long lost black sheep of the Rails family, ActionMailer. This was because I had a project that needed to use email and I found the current implementation, shall we say, somewhat lacking. This year, I’m turning my attention to really the only remaining black sheep left, ActiveResource.

ActiveResource needs to be upgraded to be a real citizen in the Rails 3 family, in fact, in the last few years there have only been very minor fixes to ActiveResource while the rest of the world moved forward.

So what do we have? Happily, working code.

ActiveResource, as it stands now, works for the simplest of cases. If you have a controller exposing a Rails REST based resource, and you point ActiveResource at it, you will be able to perform the basic CRUD operations you have come to know and love.

But if you want to go any further, you are on your own.

Associations with ActiveRecord objects don’t work, validations need attention, bulk updates and transactional support are missing entirely. The code is really as it was when it was first released.

With the world moving towards using rich clients that hit a back end API that abstracts the data layer, these things need to change. Having your front end client go to delete 100 records requiring 100 requests to complete is no fun, and a waste of time.

Sure you as a developer can dive in and create all these things. But that is the problem. With each developer rolling their own we end up with a mass of Rails apps that are all different, which increases the work load for all of us. ActiveResource must provide the same level of opinionated functionality as the rest of Rails. There needs to be a reasonable opinion on how to provide an API, a template that you can reasonably expect all Rails applications to follow.

The way I see it, there are two broad use cases for ActiveResource and the code that is exposed in the controllers. Firstly we have the “bolt on API”, this is the API that is simply added to existing controller code typically using respond_to and returning JSON or XML representations of objects.

The second type though is the pure API, these are the APIs that are built from the ground up only to talk to other systems, the API at rubygems.org is a good example of this. It is not a patch on existing functionality, but instead a core member of the entire application.

With the above in mind, I want to implement the following into ActiveResource:

  • Opinionated way to produce a “pure API” with Rails (think “rails generate api” for Rails applications that need to expose a separate, formal API for rich clients)
  • Support for bulk updates of objects to existing controllers (show_many, change_many, update_many and destroy_many) – see idea in David’s Gist
  • Transactional support for bulk operations
  • Support for multi type operations (for example, updating the post and the author at the same time) outlined in the Rails Conf talk by Yehuda Katz
  • Association support – providing connections through to local ORMs
  • Better validation handling and reliable ways to communicate error messages to client apps

The above is not an exhaustive list and I am interested in your comments. If you are interested in helping, send me an email or tweet to (@raasdnil)

I’ll be posting updates here and on my twitter feed as we move forward.

blogLater

Mikel

  1. video pool Says:

    thanks for your contributions…

  2. jeu de gestion de ferme Says:

    Natural resources are materials and components (something that can be used) that can be found within the environment. Every man-made product is composed of natural resources

  3. jeu de gestion de ferme Says:

    Natural resources are materials and components (something that can be used) that can be found within the environment. Every man-made product is composed of natural resources

  4. jack Says:

    This is essential for even trying HTTP streaming via 3.1. Are you interested in this?
    plumbers

  5. jack Says:

    This is essential for even trying HTTP streaming via 3.1. Are you interested in this?
    plumbers

  6. elecdoluxap Says:

    Great news! I hope You’ll be able to finish the work in reasonable amount of time. :)

  7. Vijay Aravamudhan Says:

    One more thing that is sorely missing is lazy eval of AResource ala ARecord. This is essential for even trying HTTP streaming via 3.1. Are you interested in this? I am planning on implementing this sometime soon (within the next couple of days) – so if you are interested, please contact me asap.

  8. Vijay Aravamudhan Says:

    One more thing that is sorely missing is lazy eval of AResource ala ARecord. This is essential for even trying HTTP streaming via 3.1. Are you interested in this? I am planning on implementing this sometime soon (within the next couple of days) – so if you are interested, please contact me asap.

  9. Vijay Aravamudhan Says:

    One more thing that is sorely missing is lazy eval of AResource ala ARecord. This is essential for even trying HTTP streaming via 3.1. Are you interested in this? I am planning on implementing this sometime soon (within the next couple of days) – so if you are interested, please contact me asap.

  10. Gabriel Sobrinho Says:

    Nice!

    I guess the associations between active resources and nested attributes are priority. At least for me :)

    Good luck!

  11. dominic Says:

    restfulie, links to find the api

  12. dominic Says:

    restfulie, links to find the api

  13. Przemek Says:

    Great news! I hope You’ll be able to finish the work in reasonable amount of time. :)

  14. Korben Dallas Says:

    Effectively it’s really necessary to improve ActiveResource!

  15. valentines day cards Says:

    This web site is really a walk-through for all of the info you wanted about this and didn’t know who to ask.

  16. is bronchitis contagious Says:

    Great news! I hope You’ll be able to finish the work in reasonable amount of time. :)

  17. How to Get Scholarships Says:

    This web site is really a walk-through for all of the info you wanted about this and didn’t know How to Get Scholarships who to ask.

  18. How to Get Scholarships Says:

    This web site is really a walk-through for all of the info you wanted about this and didn’t know How to Get Scholarships who to ask.

  19. lampioane Says:

    I was thinking switch to Ruby long time ago, but didn’t have time to start learning about it, My be now is the moment.

  20. Alimentacao Says:

    Good Work ! This is essential for even trying HTTP streaming via 3.1. Thanks for posting!

  21. thailand charter Says:

    That seems to be a good list of resources. I will use it for sure! You should post more often this kind of articles.

  22. ninjatrader Says:

    it is a good list of resources. I will use some for sure.

  23. music production Says:

    I will be sure to bookmark your blog and definitely will come back from now on. I want to encourage that you continue your great job.

  24. music production Says:

    I will be sure to bookmark your blog and definitely will come back from now on. I want to encourage that you continue your great job.

  25. sailing Says:

    One more thing that is sorely missing is lazy eval of AResource ala ARecord. This is essential for even trying HTTP streaming via 3.1. Are you interested in this?

  26. speeches Says:

    The way I see it, there are two broad use cases for ActiveResource and the code that is exposed in the controllers. Firstly we have the “bolt on API”, this is the API that is simply added to existing controller code typically using respond_to and returning JSON or XML representations of objects.

Leave a Reply