# ActionWebService for many APIs in rails?

**URL:** <https://www.ruby-forum.com/t/actionwebservice-for-many-apis-in-rails/107248>\
**Category:** Rails\
**Created:** [June 19, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/actionwebservice-for-many-apis-in-rails/107248 "2007-06-19T17:05:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@joaz](https://www.ruby-forum.com/u/joaz)\
**Post date:** [June 19, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/actionwebservice-for-many-apis-in-rails/107248/1 "2007-06-19T17:05:02Z")

</div>

Hi,

We’ve a pretty large rails application and we are currently deciding  
moving a part of the application front-end to a desktop GUI.

For communication between application and GUI we decided to use an API.  
So basically what I need is a way to have our models functionality  
accessible by the GUI.

The basic idea:

Rails app provides API for models \<-\> HTTPS Connection \<-\> GUI can  
access models with correct authentication

I took a look to ActionWebservice, but I’m not sure if this is the best  
solution.

My concern: The application has currently about 90 models. If I  
understood AWS correctly, I need to create an API class for every model  
and a ‘service’ for every model I want to serve?

Is there an automation script for this or is there a more direct  
approach to my problem ?

Thanks!

---

<div class="post-metadata">

**Author:** ![joaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@joaz](https://www.ruby-forum.com/u/joaz)\
**Post date:** [June 19, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/actionwebservice-for-many-apis-in-rails/107248/2 "2007-06-19T17:26:01Z")

</div>

You create just one class API

dir: RAILS\_ROOT/app/apis/myserver\_api.rb  
class MyserverApi \< ActionWebService::API::Base  
api\_method :list\_products,  
:expects =\> [:string],  
:returns =\> [:string]

```
api_method :list_users,
            :expects => [:string],
            :returns => [:string]

api_method :list_orders,
            :expects => [:string],
            :returns => [:string]

```

end

dir: RAILS\_ROOT/app/controller/myserver\_controller.rb  
class MyserverController \< ApplicationController  
wsdl\_service\_name ‘Myserver’  
web\_service\_api MyserverApi

```
def list_products(str)
end

def list_users(str)
end

def list_orders(str)
end

```

end

In the api you put all the method that are in the controller and after  
you use  
your models inside your controller. You can do the job with one API  
class definition or you split in more for how many controllers you  
have.

Or if you already have your controllers done, you just need to write  
some API

2007/6/19, joaz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![joaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@joaz](https://www.ruby-forum.com/u/joaz)\
**Post date:** [June 19, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/actionwebservice-for-many-apis-in-rails/107248/3 "2007-06-19T18:05:08Z")

</div>

api\_method :list, :returns =\> [[:string]]

with this returns an array with one record for each row

2007/6/19, joaz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![joaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@joaz](https://www.ruby-forum.com/u/joaz)\
**Post date:** [June 19, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/actionwebservice-for-many-apis-in-rails/107248/4 "2007-06-19T17:49:33Z")

</div>

> Or if you already have your controllers done, you just need to write  
> some API  
> Wenn 95% of all controller actions just grabs some data like

def list  
@people = Person.find(:all)  
end

I tried something like this:  
api\_method :list, :returns =\> [[Person]]

But I get an error when accessing via invoke using the SOAP protocol:  
“decimal is not a valid base type” on numeric fields in our postgresql  
database.

---

<div class="post-metadata">

**Author:** ![joaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@joaz](https://www.ruby-forum.com/u/joaz)\
**Post date:** [June 19, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/actionwebservice-for-many-apis-in-rails/107248/5 "2007-06-19T18:17:54Z")

</div>

claudio wrote:

> api\_method :list, :returns =\> [[:string]]
> 
> with this returns an array with one record for each row

well in my case this returns an array with Object.to\_s  
["#Person:0xb701e23c", “#Person:0xb701e0d4”,…]
