Hi, I have a Rails 2 app and I wand to provide an API for 3rd party applications written on any language the customer uses. My thoughts are that the best way of providing it is by taking advantage of rails RESTfulness and let them perform CRUD actions on my data through it. But I don''t seem to find many information on how to achieve this. I first want to develop .NET clients (or web service consumers) because must of our customers use .NET. I did some prototypes and could retrieve XML data, but I don''t seem to find a way of doing inserts, updates and deletes. What I get is a 422 http error from the rails server and I assume has something to do with the Header. Where can I find more information about this. More specificlly about what the server is expecting to receive in the header and the message. Also, if someone has experience on WCF and can point me out where to find more valuable info it will be appreciated. Java examples will work as well. Thanks, Roberto --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 19, 12:22 pm, Roberto <roberto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a Rails 2 app and I wand to provide an API for 3rd party > applications written on any language the customer uses. > > My thoughts are that the best way of providing it is by taking > advantage of rails RESTfulness and let them perform CRUD actions on my > data through it. But I don''t seem to find many information on how to > achieve this.Definitely. Your controller can provide an out-of-the-box API by examining the HTTP accept header and returning XML. Rails wraps this up for you automatically if you use the respond_to method in your controller: def index @things = Thing.find(:all) respond_to do |format| format.html # render template format.xml { render :xml => @things.to_xml } end end This example is a bit simplistic but demonstrates the principle of how you can return XML instead of HTML based on the http header.> I first want to develop .NET clients (or web service consumers) > because must of our customers use .NET. I did some prototypes and > could retrieve XML data, but I don''t seem to find a way of doing > inserts, updates and deletes. > What I get is a 422 http error from the rails server and I assume has > something to do with the Header. > Where can I find more information about this. More specificlly about > what the server is expecting to receive in the header and the message. >Make sure you''re setting the accept and content-type headers correctly to "text/xml" or "application/xml". That''s the clue Rails needs to trigger the right action in your respond_to block. We actually have a chapter on doing this exact thing in our upcoming book, Rails for .NET Developers (http://pragprog.com/titles/cerailn).> > Also, if someone has experience on WCF and can point me out where to > find more valuable info it will be appreciated. > > Java examples will work as well.You may find our upcoming class helpful, as we touch on RESTful web service creation in Rails: http://www.purpleworkshops.com/workshops/rest-and-web-services (you can use discount code "PWRRGG" for 10% off). Hope this helps a bit? Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeff, I think I didn''t explain myself correctly or was at some point misleading. I do have the service up and running and working with XML already. From C# code I can do all the GET methods and get the XML responses, for example: - for retrieving 1 record: GET request to http://localhost:3000/resources/1.xml - for doing the first step on adding a record: GET request to http://172.16.30.117:3000/resources/new.xml but when trying to perform a POST to http://172.16.30.117:3000/resources.xmlpassing the new XML with values in it as the request content it returns the 422 error. I see that the header coming from the ruby server has session info and stuff which I''m assuming I have to use for posting back. Now I know creating or updating isn''t as simple as retrieving (which was pretty easy). As a start I''ll read the following which I think will be useful: http://blogs.vertigo.com/personal/petar/Blog/archive/2008/06/23/twitter-wcf-client.aspx I also found an open source WPF project that may help me as a guide: http://sourceforge.net/projects/twitterful/ Will your chapter cover this subject? What will the integrating with .NET cover? Looking forward to see your book and also coperate with what myself and my team achieve. Thank you! Roberto On Fri, Sep 19, 2008 at 12:29 PM, Jeff <cohen.jeff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Sep 19, 12:22 pm, Roberto <roberto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > > I have a Rails 2 app and I wand to provide an API for 3rd party > > applications written on any language the customer uses. > > > > My thoughts are that the best way of providing it is by taking > > advantage of rails RESTfulness and let them perform CRUD actions on my > > data through it. But I don''t seem to find many information on how to > > achieve this. > > Definitely. Your controller can provide an out-of-the-box API by > examining the HTTP accept header and returning XML. Rails wraps this > up for you automatically if you use the respond_to method in your > controller: > > def index > @things = Thing.find(:all) > respond_to do |format| > format.html # render template > format.xml { render :xml => @things.to_xml } > end > end > > This example is a bit simplistic but demonstrates the principle of how > you can return XML instead of HTML based on the http header. > > > I first want to develop .NET clients (or web service consumers) > > because must of our customers use .NET. I did some prototypes and > > could retrieve XML data, but I don''t seem to find a way of doing > > inserts, updates and deletes. > > What I get is a 422 http error from the rails server and I assume has > > something to do with the Header. > > Where can I find more information about this. More specificlly about > > what the server is expecting to receive in the header and the message. > > > > Make sure you''re setting the accept and content-type headers correctly > to "text/xml" or "application/xml". That''s the clue Rails needs to > trigger the right action in your respond_to block. We actually have a > chapter on doing this exact thing in our upcoming book, Rails for .NET > Developers (http://pragprog.com/titles/cerailn). > > > > > Also, if someone has experience on WCF and can point me out where to > > find more valuable info it will be appreciated. > > > > Java examples will work as well. > > You may find our upcoming class helpful, as we touch on RESTful web > service creation in Rails: > http://www.purpleworkshops.com/workshops/rest-and-web-services > (you can use discount code "PWRRGG" for 10% off). > > Hope this helps a bit? > > Jeff > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you haven''t already, have a look at the client section of this article here: http://msdn.microsoft.com/en-us/magazine/cc748663.aspx If I skim that correctly ;-) it sounds like the ado.net data services client library speaks REST... -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Jeff Sent: Friday, September 19, 2008 11:30 AM To: Ruby on Rails: Talk Subject: [Rails] Re: Non-Ruby REST client for Ruby REST server On Sep 19, 12:22 pm, Roberto <roberto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a Rails 2 app and I wand to provide an API for 3rd party > applications written on any language the customer uses. > > My thoughts are that the best way of providing it is by taking > advantage of rails RESTfulness and let them perform CRUD actions on my > data through it. But I don''t seem to find many information on how to > achieve this.Definitely. Your controller can provide an out-of-the-box API by examining the HTTP accept header and returning XML. Rails wraps this up for you automatically if you use the respond_to method in your controller: def index @things = Thing.find(:all) respond_to do |format| format.html # render template format.xml { render :xml => @things.to_xml } end end This example is a bit simplistic but demonstrates the principle of how you can return XML instead of HTML based on the http header.> I first want to develop .NET clients (or web service consumers) > because must of our customers use .NET. I did some prototypes and > could retrieve XML data, but I don''t seem to find a way of doing > inserts, updates and deletes. > What I get is a 422 http error from the rails server and I assume has > something to do with the Header. > Where can I find more information about this. More specificlly about > what the server is expecting to receive in the header and the message. >Make sure you''re setting the accept and content-type headers correctly to "text/xml" or "application/xml". That''s the clue Rails needs to trigger the right action in your respond_to block. We actually have a chapter on doing this exact thing in our upcoming book, Rails for .NET Developers (http://pragprog.com/titles/cerailn).> > Also, if someone has experience on WCF and can point me out where to > find more valuable info it will be appreciated. > > Java examples will work as well.You may find our upcoming class helpful, as we touch on RESTful web service creation in Rails: http://www.purpleworkshops.com/workshops/rest-and-web-services (you can use discount code "PWRRGG" for 10% off). Hope this helps a bit? Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sounds to me like you aren''t setting the HTTP Method on your client side update/insert/delete requests. For example in curl you would do this with -X => curl -X delete http://server/resource/2 to delete resource 2 Sounds to me like you are sending GET requests to an action that expects something different Say you want to delete a resource 4 on localhost The header should resemble roughly something like this.> delte / HTTP/1.1 > User-Agent: curl/7.19.0 (i386-apple-darwin9.4.0) libcurl/7.19.0 zlib/1.2.3 > Host: localhost > Accept: */*I''m not sure about how you want to write the client but you can also include a request param "_method" and give it the corresponding HTTP method. (PUT, POST, DELTE etc.) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I found out that what was not letting me do the POST/PUT''s is: "protect_from_forgery" because of the authenticity token needed. Now I need to know if there''s a workaround for this without having to stop using this method. Thanks! On Sep 19, 12:57 pm, "Roberto Fernandez" <roberto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Jeff, > > I think I didn''t explain myself correctly or was at some point misleading. > I do have the service up and running and working with XML already. > > From C# code I can do all the GET methods and get the XML responses, for > example: > > - for retrieving 1 record: GET request to > http://localhost:3000/resources/1.xml > - for doing the first step on adding a record: GET request to > http://172.16.30.117:3000/resources/new.xml > > but when trying to perform a POST tohttp://172.16.30.117:3000/resources.xmlpassingthe new XML with values > in it as the request content it returns the > 422 error. I see that the header coming from the ruby server has session > info and stuff which I''m assuming I have to use for posting back. > > Now I know creating or updating isn''t as simple as retrieving (which was > pretty easy). As a start I''ll read the following which I think will be > useful:http://blogs.vertigo.com/personal/petar/Blog/archive/2008/06/23/twitt... > > I also found an open source WPF project that may help me as a guide:http://sourceforge.net/projects/twitterful/ > > Will your chapter cover this subject? What will the integrating with .NET > cover? Looking forward to see your book and also coperate with what myself > and my team achieve. > > Thank you! > > Roberto > > On Fri, Sep 19, 2008 at 12:29 PM, Jeff <cohen.j...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Sep 19, 12:22 pm, Roberto <roberto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > > I have a Rails 2 app and I wand to provide an API for 3rd party > > > applications written on any language the customer uses. > > > > My thoughts are that the best way of providing it is by taking > > > advantage of rails RESTfulness and let them perform CRUD actions on my > > > data through it. But I don''t seem to find many information on how to > > > achieve this. > > > Definitely. Your controller can provide an out-of-the-box API by > > examining the HTTP accept header and returning XML. Rails wraps this > > up for you automatically if you use the respond_to method in your > > controller: > > > def index > > @things = Thing.find(:all) > > respond_to do |format| > > format.html # render template > > format.xml { render :xml => @things.to_xml } > > end > > end > > > This example is a bit simplistic but demonstrates the principle of how > > you can return XML instead of HTML based on the http header. > > > > I first want to develop .NET clients (or web service consumers) > > > because must of our customers use .NET. I did some prototypes and > > > could retrieve XML data, but I don''t seem to find a way of doing > > > inserts, updates and deletes. > > > What I get is a 422 http error from the rails server and I assume has > > > something to do with the Header. > > > Where can I find more information about this. More specificlly about > > > what the server is expecting to receive in the header and the message. > > > Make sure you''re setting the accept and content-type headers correctly > > to "text/xml" or "application/xml". That''s the clue Rails needs to > > trigger the right action in your respond_to block. We actually have a > > chapter on doing this exact thing in our upcoming book, Rails for .NET > > Developers (http://pragprog.com/titles/cerailn). > > > > Also, if someone has experience on WCF and can point me out where to > > > find more valuable info it will be appreciated. > > > > Java examples will work as well. > > > You may find our upcoming class helpful, as we touch on RESTful web > > service creation in Rails: > >http://www.purpleworkshops.com/workshops/rest-and-web-services > > (you can use discount code "PWRRGG" for 10% off). > > > Hope this helps a bit? > > > Jeff--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
fervic wrote:> I found out that what was not letting me do the POST/PUT''s is: > > "protect_from_forgery" > > because of the authenticity token needed. > > Now I need to know if there''s a workaround for this without having to > stop using this method. > > > Thanks!Hi, I came across this problem and the solution is quite simple. Bumping this topic for other poor googling souls. Just put skip_before_filter :verify_authenticity_token in your controller. See the docs for ActionController::RequestForgeryProtection for more info; you could also override that method instead if you wanted to do something specific for non-verified clients. James -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of James Salter > Sent: Tuesday, October 21, 2008 4:42 PM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] Re: Non-Ruby REST client for Ruby REST server > > > fervic wrote: > > I found out that what was not letting me do the POST/PUT''s is: > > > > "protect_from_forgery" > > > > because of the authenticity token needed. > > > > Now I need to know if there''s a workaround for this without having to > > stop using this method. > > > > > > Thanks! > > Hi, > > I came across this problem and the solution is quite simple. Bumping this > topic for other poor googling souls. > > Just put skip_before_filter :verify_authenticity_token in your controller. > > See the docs for ActionController::RequestForgeryProtection for more info; you > could also override that method instead if you wanted to do something specific > for non-verified clients. >So does that leave the forgery protection in place for browser clients? Thanks! -Roy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---