# Web api question

**URL:** <https://www.ruby-forum.com/t/web-api-question/108589>\
**Category:** Rails\
**Created:** [July 5, 2007, 4:51am UTC](https://www.ruby-forum.com/t/web-api-question/108589 "2007-07-05T04:51:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [July 5, 2007, 4:51am UTC](https://www.ruby-forum.com/t/web-api-question/108589/1 "2007-07-05T04:51:22Z")

</div>

I’m looking at the best type of api to create for a particular  
project. Although this isn’t really ruby/rails specific other then it  
will be written in ruby, it’s probably an area that many people on  
this list deal with.

The api is delivering information that will primarily be displayed in  
report and list formats. Customers, orders, transaction histories,  
etc… The end use is that the content for a web interface will be  
fetched via this api. It will be integrated into many different  
types of software in different languages.

My first thought was to use xml for the data format. Good points are  
that it’s well known and it’s easy to represent nested data  
structures. The bad side is that leaves quite a bit of work to  
implement it on the end user side.

The other idea was to let users create html templates on the server  
side using a simple language, or maybe even something like erb. This  
would move a lot of the processing to the server end, but make things  
a lot easier for end users that just want the easiest way to display a  
list or report. Xml could always be an option for those that want it.

I’m also playing around with the idea of an activerecord adaptor  
specific to the data set we will have available. There will also be  
request types that can modify data in our system as well as retrieve  
it, and an activerecord adaptor would make it easy for rails folks to  
plug into their own rails apps.

Any other ideas are appreciated!

Chris

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [July 5, 2007, 5:08am UTC](https://www.ruby-forum.com/t/web-api-question/108589/2 "2007-07-05T05:08:23Z")

</div>

snacktime wrote:

> My first thought was to use xml for the data format. Good points are  
> that it’s well known and it’s easy to represent nested data  
> structures. The bad side is that leaves quite a bit of work to  
> implement it on the end user side.

The other side can trivially convert XML into XHTML using XSLT. You can  
bootstrap them by delivering basic XSLT files.

> The other idea was to let users create html templates on the server  
> side using a simple language, or maybe even something like erb. This  
> would move a lot of the processing to the server end, but make things  
> a lot easier for end users that just want the easiest way to display a  
> list or report. Xml could always be an option for those that want it.

That would expose your database to their find() skills.

> I’m also playing around with the idea of an activerecord adaptor  
> specific to the data set we will have available. There will also be  
> request types that can modify data in our system as well as retrieve  
> it, and an activerecord adaptor would make it easy for rails folks to  
> plug into their own rails apps.

That means they would need to write their own sites in Rails. Don’t you  
mean  
an ODBC adapter, for a lower level?

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [July 19, 2007, 10:33pm UTC](https://www.ruby-forum.com/t/web-api-question/108589/3 "2007-07-19T22:33:54Z")

</div>

Dear Railers,

I’m working on a web application that controls media players over the  
internet. The app needs to send and receive AJAX XHR requests/responses  
formatted as JSON objects.

These are not directly related to the standard CRUD screens, but will be  
used to issue commands to multiple clients, from an AJAX JSON request  
that contains a command and an array of client names.

The server will also need to generate AJAX JSON responses, containing a  
client name along with an array of fields whose data has changed. These  
are to be parsed on the client and will update cells in a table  
indicating the current state of individual clients.

Since I haven’t done this before, I’m trying to understand if there is a  
place in the current rails code that I should hook into, or if I need a  
new controller to handle the AJAX requests/responses.

Any suggestions or code samples of others who have tackled this issue  
would be greatly appreciated. To get a better understanding of what the  
App is up to, you can view it at: [http://24.23.248.71](http://24.23.248.71)  
The page that this problem refers to is here:  
[http://24.23.248.71/wm/public/index.html](http://24.23.248.71/wm/public/index.html) If you’ve got Firebug running,  
you’ll see the command generated in the Console window, provided at  
least one client is checked.

Any pointers, code examples, or explanations as to how this might or  
should be done are sincerely appreciated.

Thanks,

– Steve

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [July 5, 2007, 5:48am UTC](https://www.ruby-forum.com/t/web-api-question/108589/4 "2007-07-05T05:48:25Z")

</div>

> The other side can trivially convert XML into XHTML using XSLT. You can  
> bootstrap them by delivering basic XSLT files.

I’m biased on this one. If people ask for it I’d consider it, but  
frankly I don’t think your average developer considers xslt trivial.

> > The other idea was to let users create html templates on the server  
> > side using a simple language, or maybe even something like erb. This  
> > would move a lot of the processing to the server end, but make things  
> > a lot easier for end users that just want the easiest way to display a  
> > list or report. Xml could always be an option for those that want it.
> 
> That would expose your database to their find() skills.

All applications get their data delivered as xml except for the layer  
that translates data going in and out of the database. In addition  
even that layer can only call stored procedures with strict data  
types. It has a fair amount of extra security above and beyond what  
you would see in a normal web app.

> > I’m also playing around with the idea of an activerecord adaptor  
> > specific to the data set we will have available. There will also be  
> > request types that can modify data in our system as well as retrieve  
> > it, and an activerecord adaptor would make it easy for rails folks to  
> > plug into their own rails apps.
> 
> That means they would need to write their own sites in Rails. Don’t you mean  
> an ODBC adapter, for a lower level?

It would basically define a set of models it supports, and map  
supported methods into api calls back to our system. Or something  
similar I haven’t thought it through all the way. No sql at all  
though. At first it would be ruby only, but once the mapping is done  
in activerecord it could be modified to work with similar systems in  
any language. Granted this would probably be a feature added later  
on, just kind of thinking out loud.

Chris
