# Where do i put the code to pull data from an API?

**URL:** <https://www.ruby-forum.com/t/where-do-i-put-the-code-to-pull-data-from-an-api/111046>\
**Category:** Rails\
**Created:** [August 2, 2007, 5:47am UTC](https://www.ruby-forum.com/t/where-do-i-put-the-code-to-pull-data-from-an-api/111046 "2007-08-02T05:47:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koalemos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@Koalemos](https://www.ruby-forum.com/u/Koalemos)\
**Post date:** [August 2, 2007, 5:47am UTC](https://www.ruby-forum.com/t/where-do-i-put-the-code-to-pull-data-from-an-api/111046/1 "2007-08-02T05:47:58Z")

</div>

My app doesnt use a database, it gets all it’s information from an  
api. I was wondering whether i should put the code for pulling the api  
data into an array in the controller or a model?

This is a pretty simple app right now with only one controller, I may  
expand it later but I have no plans to do so right now.

---

<div class="post-metadata">

**Author:** ![Koalemos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@Koalemos](https://www.ruby-forum.com/u/Koalemos)\
**Post date:** [August 2, 2007, 6:06am UTC](https://www.ruby-forum.com/t/where-do-i-put-the-code-to-pull-data-from-an-api/111046/2 "2007-08-02T06:06:13Z")

</div>

Koalemos wrote:

> My app doesnt use a database, it gets all it’s information from an  
> api. I was wondering whether i should put the code for pulling the api  
> data into an array in the controller or a model?
> 
> This is a pretty simple app right now with only one controller, I may  
> expand it later but I have no plans to do so right now.

I’m curious what others say. I’m going to be in the same boat in a few  
days. But it sounds like a model to me. The API to fetch the data is  
logically the same as the API to the database methods to fetch the data.

Thats my thought anyway.

---

<div class="post-metadata">

**Author:** ![Koalemos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@Koalemos](https://www.ruby-forum.com/u/Koalemos)\
**Post date:** [August 2, 2007, 7:01am UTC](https://www.ruby-forum.com/t/where-do-i-put-the-code-to-pull-data-from-an-api/111046/3 "2007-08-02T07:01:02Z")

</div>

In the model,  
All your data objects should be in the models, and the controller is  
simply a bridge between the models and the views, pooling out only the  
data the view needs, so you’d write methods for retrieving and  
creating data in your model and then call those functions in your  
controllers and parse those arrays etc into your views.

Cam

---

<div class="post-metadata">

**Author:** ![Koalemos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@Koalemos](https://www.ruby-forum.com/u/Koalemos)\
**Post date:** [August 3, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/where-do-i-put-the-code-to-pull-data-from-an-api/111046/4 "2007-08-03T19:50:41Z")

</div>

Definitely in a model. Here’s the Rails hint: ActiveResource::Base  
(edge/2.0) is similar to ActiveRecord::Base.
