What if I have an API method and a contoller/view method with the same name in RoR?

Posted by Chad Johnson on Stack Overflow See other posts from Stack Overflow or by Chad Johnson
Published on 2010-04-01T18:00:06Z Indexed on 2010/04/01 18:03 UTC
Read the original article Hit count: 267

Filed under:
|

Suppose I want to be able to view a list of products on my site by going to /product/list. Great. So this uses my 'list' view and outputs some HTML which my web browser will render.

But now suppose I want to provide a REST API to my client where they can get a list of their products. So I suppose I'd have them authenticate with oAuth and then they'd call /product/list which would return a JSON array of their products.

But like I said earlier, /product/list displays an HTML web page. So, I have a conflict.

What is normal practice as far as providing APIs in Rails? Should I have a subdirectory, 'api', in /app/controller, and another 'product' controller? So my client would go to /api/product/list to get a list of their products?

I'm a bit new to RoR, so I don't have the best grasp of the REST functionality yet, but hopefully my question makes sense.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about api