Request spec for XML API

27 views
Skip to first unread message

josep...@gmail.com

unread,
Oct 12, 2020, 11:14:38 AM10/12/20
to rspec
Hi.

I need to create an API that will accept XML. How can I specify an XML body in a request spec? I have tried:

data = (xml as a string)
post '/api/path', env: { 'RAW_POST_BODY' => data, 'Content-Type' => 'text/xml' }

and then I can access the body as request.body.read but the values do not appear in the params. Obviously, I could pass the parameters with 'params: { key: value, ... }' but I'd prefer to be able to test with samples of the body as they are going to be sent.

Regards,

Joe

Phil Pirozhkov

unread,
Oct 12, 2020, 11:23:43 AM10/12/20
to Jack Royal-Gordon
So I guess it should be:
```
post "/api/path", params: data, headers: { "CONTENT_TYPE" => "text/xml" }
```

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/10d88f3c-eb7b-47f3-94f6-e6b5b14aff10n%40googlegroups.com.

Joseph Haig

unread,
Oct 12, 2020, 12:35:05 PM10/12/20
to rs...@googlegroups.com
Thanks! That worked perfectly. I had seen that but I didn't notice that the parameters in that example were a JSON string, so I thought it was still being defined as a hash.

Reply all
Reply to author
Forward
0 new messages