# Web service client code layout -- standard practice

**URL:** <https://www.ruby-forum.com/t/web-service-client-code-layout-standard-practice/184305>\
**Category:** Rails\
**Created:** [February 28, 2010, 4:59pm UTC](https://www.ruby-forum.com/t/web-service-client-code-layout-standard-practice/184305 "2010-02-28T16:59:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![smarter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@smarter](https://www.ruby-forum.com/u/smarter)\
**Post date:** [February 28, 2010, 4:59pm UTC](https://www.ruby-forum.com/t/web-service-client-code-layout-standard-practice/184305/1 "2010-02-28T16:59:59Z")

</div>

Hi:

Where do you all think the web service client code (for a REST service)  
access fit in a Rails App?  
Models are what Controllers call and should probably do so now also even  
though its Non-Active Record.

However, Models use the web service REST Access code to get XML and  
parse it to give ActiveRecord style responses to controller.

Where should the Net:Http connection style requests be made–  
in lib or initializer requiring lib or as create as a new plugin?

Where does the parsing of XML code happen-- in Model Itself?

Is the Rails Helper directory directed more towards views helpful here?

Getting it done could be easy to do everything in controller. However,  
want to make it more well designed and scaleable from future  
perspective. Hence, above code layout questions.

Please advise based on experiences.

Thanks in Advance.

---

<div class="post-metadata">

**Author:** ![smarter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@smarter](https://www.ruby-forum.com/u/smarter)\
**Post date:** [February 28, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/web-service-client-code-layout-standard-practice/184305/2 "2010-02-28T20:30:31Z")

</div>

You might like

httparty for this (instead of Net:Http)

I think a good place - if you are only doing it it one place - is the  
model  
you use it  
in - with a test around that model.

If you are doing more than that and you are building a tool for this  
then  
the lib directory.

---

<div class="post-metadata">

**Author:** ![smarter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@smarter](https://www.ruby-forum.com/u/smarter)\
**Post date:** [February 28, 2010, 9:38pm UTC](https://www.ruby-forum.com/t/web-service-client-code-layout-standard-practice/184305/3 "2010-02-28T21:38:09Z")

</div>

Curtis S. wrote:

> You might like
> 
> httparty for this (instead of Net:Http)
> 
> I think a good place - if you are only doing it it one place - is the  
> model  
> you use it  
> in - with a test around that model.
> 
> If you are doing more than that and you are building a tool for this  
> then  
> the lib directory.

Thank you. Will see the mentioned gem.

---

<div class="post-metadata">

**Author:** ![smarter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@smarter](https://www.ruby-forum.com/u/smarter)\
**Post date:** [March 1, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/web-service-client-code-layout-standard-practice/184305/4 "2010-03-01T14:46:29Z")

</div>

Smart RoR wrote:

> I guess ActiveResource is restrictive if you don’t have control on the  
> WebService API.
> 
> Net::Http is most flexible but no parsing done for you.
> 
> Httparty seems nice. It uses Crack gem for XML parsing, that is better  
> than Rexml and Hpricot in terms of parsing I think. Of course, libxml is  
> the fastest but this good too.
> 
> In the end, use depending on what works for you based on your  
> requirements.

And yes, Httparty uses Net:Http under the hood, so you know it is  
reliable for the basic calls…🙂

---

<div class="post-metadata">

**Author:** ![smarter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@smarter](https://www.ruby-forum.com/u/smarter)\
**Post date:** [March 1, 2010, 2:45pm UTC](https://www.ruby-forum.com/t/web-service-client-code-layout-standard-practice/184305/5 "2010-03-01T14:45:44Z")

</div>

I guess ActiveResource is restrictive if you don’t have control on the  
WebService API.

Net::Http is most flexible but no parsing done for you.

Httparty seems nice. It uses Crack gem for XML parsing, that is better  
than Rexml and Hpricot in terms of parsing I think. Of course, libxml is  
the fastest but this good too.

In the end, use depending on what works for you based on your  
requirements.
