# ActiveResource as API test rig?

**URL:** <https://www.ruby-forum.com/t/activeresource-as-api-test-rig/168461>\
**Category:** Rails\
**Created:** [May 21, 2009, 12:58am UTC](https://www.ruby-forum.com/t/activeresource-as-api-test-rig/168461 "2009-05-21T00:58:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [May 21, 2009, 12:58am UTC](https://www.ruby-forum.com/t/activeresource-as-api-test-rig/168461/1 "2009-05-21T00:58:29Z")

</div>

Hi,

I’m using ActiveResource as an API test rig for an API we’re developing  
for  
our PHP app - the goal being to validate that we’re following some  
externally validated conventions for ReSTful API and that we can support  
at  
least one external framework. ;^) I’m open to opinions on the wisdom  
of  
this approach.

Meanwhile, I’m getting some strange behavior when running from command  
line  
vs. running w/in rails:

First, from command line:  
require ‘rubygems’  
require ‘activesupport’  
require ‘activeresource’

class Channel \< ActiveResource::Base  
self.site = “[http://192.168.1.101/](http://192.168.1.101/)”  
self.format = :json  
end

c = Channel.find(:all , :params =\> {:owner =\> “iamwill”})

Result is:  
/var/lib/gems/1.8/gems/activesupport-2.3.2/lib/active\_support/json/decoding.rb:14:in  
`decode': Invalid JSON string (ActiveSupport::JSON::ParseError) from /var/lib/gems/1.8/gems/activeresource-2.3.2/lib/active_resource/formats/json_format.rb:19:in `decode’  
from  
/var/lib/gems/1.8/gems/activeresource-2.3.2/lib/active\_resource/connection.rb:116:in  
`get' from /var/lib/gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:576:in `find\_every’  
from  
/var/lib/gems/1.8/gems/activeresource-2.3.2/lib/active\_resource/base.rb:519:in  
`find’  
from channels.rb:10

But when I run from rails, it parses no problem.

I gave the rails version malformed json to cause it to choke to figure  
out  
the difference:

vendor/rails/activesupport/lib/active\_support/json/decoding.rb:14:in  
`decode’

Is it possible to coerce the non-rails version to use the rails json  
parser? Why are there two different versions?

Thanks,

m
