Configure restful web service in rails

19 views
Skip to first unread message

prabhu

unread,
Apr 16, 2014, 8:34:42 AM4/16/14
to rubyonra...@googlegroups.com
Hi,

I am trying to create a Rest web service in my rails application. I need to configure urls for it as below.


    localhost:3000/book/book_id/new/param1/param2/param3/param4/...
   
    localhost:3000/book/book_id/next
   
    localhost:3000/book/book_id/delete

I dont have a view pages for it since it returns in json format.Please help.So what is the best way to configure these urls via routes.




prabhu

unread,
Apr 16, 2014, 8:36:58 AM4/16/14
to rubyonra...@googlegroups.com

Colin Law

unread,
Apr 16, 2014, 8:47:27 AM4/16/14
to rubyonra...@googlegroups.com
On 16 April 2014 13:34, prabhu <pradeep....@gmail.com> wrote:
> Hi,
>
> I am trying to create a Rest web service in my rails application. I need to
> configure urls for it as below.
>
>
> localhost:3000/book/book_id/new/param1/param2/param3/param4/...

That might be better as book/id/new?param1=..&param2=.. etc.
What is that url supposed to do? If it makes a new book then why have
you got an id?

>
> localhost:3000/book/book_id/next
>
> localhost:3000/book/book_id/delete
>
> I dont have a view pages for it since it returns in json format.Please
> help.So what is the best way to configure these urls via routes.

Read the Rails Guide on Routing, that should explain how to do it. If
there is something there you do not understand then come back and ask
about it.

Colin

Robert Walker

unread,
Apr 16, 2014, 9:55:42 AM4/16/14
to rubyonra...@googlegroups.com
Colin Law wrote in post #1143272:
> On 16 April 2014 13:34, prabhu <pradeep....@gmail.com> wrote:
>> Hi,
>>
>> I am trying to create a Rest web service in my rails application. I need to
>> configure urls for it as below.
>>
>>
>> localhost:3000/book/book_id/new/param1/param2/param3/param4/...
>
> That might be better as book/id/new?param1=..&param2=.. etc.
> What is that url supposed to do? If it makes a new book then why have
> you got an id?

As Colin noted, if this is intended to create a new book then it seems
more logical to me to send this as a POST with the parameters in the
body of the request (either supplied as form data or JSON) and not in
the GET style of appending the parameters to the URI.

--
Posted via http://www.ruby-forum.com/.

Jordon Bedwell

unread,
Apr 16, 2014, 10:06:49 AM4/16/14
to rubyonra...@googlegroups.com
One should not accept JSON input outside of a API interface built with
REST semantics because then you are just muddying the waters and
enforcing multiple types for something that is probably purely for
HTML and doesn't even need a secondary type. It's a bad idea to
combine your API REST and REST interfaces for HTML into the same
endpoints.
Reply all
Reply to author
Forward
0 new messages