Conceptual question about body vs params

25 views
Skip to first unread message

rgagnon

unread,
Apr 11, 2011, 9:51:42 AM4/11/11
to Service Oriented Design With Ruby
Hello,

I bought the book Service Oriented Design with ruby and rails and we
are about to create some web services. We want to start it the right
way.

Here is my question :

My web service will receive an xml as the request that we need to
parse or add or change some stuffs in it and call an external service
with it. We will do same thing with the response(parsing, add or
change stuff) then return it back to the caller in a internal standard
response. The xml has to be in the body on as form field xml_field
for instance?

If its in the body, to test it in rspec, we need to pass it like
this ? :

request.env['RAW_POST_DATA'] = '<test>test</test>'

Suggestions?

Our server is with rails 3.

Thank for the great book btw.

Paul Dix

unread,
Apr 11, 2011, 10:06:16 AM4/11/11
to service-oriented...@googlegroups.com
If you're POSTing XML you shouldn't do it as form data. You do this by
setting the "Content-Type" header in the request. For regular form
POSTs this is application/x-www-form-urlencoded. With yours you want
to set it to application/xml. In your tests you can just set the
request body to the xml itself.

Is this a new application? The reason I ask is because I would NEVER
use XML if I could avoid it. If it's a new application and you have
control over the API, use JSON instead. It's easier to work with and
it parses faster.

Best,
Paul

> --
> You received this message because you are subscribed to the Google Groups "Service Oriented Design With Ruby" group.
> To post to this group, send email to service-oriented...@googlegroups.com.
> To unsubscribe from this group, send email to service-oriented-desig...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/service-oriented-design-with-ruby?hl=en.
>
>

Jason Dixon

unread,
Apr 11, 2011, 10:08:38 AM4/11/11
to service-oriented...@googlegroups.com
On Mon, Apr 11, 2011 at 10:06:16AM -0400, Paul Dix wrote:
> If you're POSTing XML you shouldn't do it as form data. You do this by
> setting the "Content-Type" header in the request. For regular form
> POSTs this is application/x-www-form-urlencoded. With yours you want
> to set it to application/xml. In your tests you can just set the
> request body to the xml itself.
>
> Is this a new application? The reason I ask is because I would NEVER
> use XML if I could avoid it. If it's a new application and you have
> control over the API, use JSON instead. It's easier to work with and
> it parses faster.

+1 (and more if I have spare karma)

-J.



> Best,
> Paul
>
> On Mon, Apr 11, 2011 at 9:51 AM, rgagnon <rem.g...@gmail.com> wrote:
> > Hello,
> >
> > I bought the book Service Oriented Design with ruby and rails and we

> > are about to create some web services. ?We want to start it the right


> > way.
> >
> > Here is my question :
> >
> > My web service will receive an xml as the request that we need to
> > parse or add or change some stuffs in it and call an external service

> > with it. ?We will do same thing with the response(parsing, add or


> > change stuff) then return it back to the caller in a internal standard

> > response. ?The xml has to be in the body on as form field xml_field


> > for instance?
> >
> > If its in the body, to test it in rspec, we need to pass it like
> > this ? :
> >
> > request.env['RAW_POST_DATA'] = '<test>test</test>'
> >
> > Suggestions?
> >
> > Our server is with rails 3.
> >
> > Thank for the great book btw.
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Service Oriented Design With Ruby" group.
> > To post to this group, send email to service-oriented...@googlegroups.com.
> > To unsubscribe from this group, send email to service-oriented-desig...@googlegroups.com.
> > For more options, visit this group at http://groups.google.com/group/service-oriented-design-with-ruby?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Service Oriented Design With Ruby" group.
> To post to this group, send email to service-oriented...@googlegroups.com.
> To unsubscribe from this group, send email to service-oriented-desig...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/service-oriented-design-with-ruby?hl=en.
>

--
Jason Dixon
DixonGroup Consulting
http://www.dixongroup.net/

Remi Gagnon

unread,
Apr 11, 2011, 10:26:44 AM4/11/11
to service-oriented...@googlegroups.com
Thank you for the quick answer.

We will try this out today.

Since the client and the external provider are already coded using xml interface we have to stick with it unfortunately.

Keep you in touch.

Rémi

Remi Gagnon

unread,
Apr 11, 2011, 4:39:50 PM4/11/11
to service-oriented...@googlegroups.com
Hi,

Here is the code, that's the only I figured out to make it works

Is it clean?

describe EnqueteCreditController do

  describe "Requête avec réponse valide" do

    it "should be successful" do

      request.env['content_type'] = 'application/xml'

      request.env['RAW_POST_DATA'] =  '<enquete><id>1</id></enquete>'

      post :create, :format => :xml

      response.should be_success

    end

  end

end

Reply all
Reply to author
Forward
0 new messages