# How do you test your REST API with XML?

**URL:** <https://www.ruby-forum.com/t/how-do-you-test-your-rest-api-with-xml/92156>\
**Category:** Rails\
**Created:** [April 16, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/how-do-you-test-your-rest-api-with-xml/92156 "2007-04-16T18:17:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [April 16, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/how-do-you-test-your-rest-api-with-xml/92156/1 "2007-04-16T18:17:08Z")

</div>

So far I’ve been manually using curl to make get and post requests  
against my Rails app to see if I’m responding to XML clients  
correctly.

But this is silly, I need to write unit tests. I don’t see an obvious  
way to do this in Rails unit tests. I’m about to invent an  
‘xml\_fixtures’ helper method that will pull in some hardcoded XML  
files, and then use those to make post requests and/or make sure I get  
the expected XML back from the server.

But before I invest the time - is there a better way?

Thanks  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [April 16, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/how-do-you-test-your-rest-api-with-xml/92156/2 "2007-04-16T18:42:12Z")

</div>

You can do it with integration tests, but I agree that there ought to  
be a lower-level approach

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [April 16, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/how-do-you-test-your-rest-api-with-xml/92156/3 "2007-04-16T18:42:11Z")

</div>

* * *

get(path, parameters=nil, headers=nil)  
Performs a GET request with the given parameters. The parameters may  
be nil, a Hash, or a string that is appropriately encoded (application/  
x-www-form-urlencoded or multipart/form-data). The headers should be a  
hash. The keys will automatically be upcased, with the prefix ‘HTTP\_’  
added if needed.

## You can also perform POST, PUT, DELETE, and HEAD requests with post, put, delete, and head.

You can use all the REST verbs from within your functional and  
integration tests. You should be able to set your ACCEPTS header to  
have the call return whatever format you want to test against.

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [April 16, 2007, 6:46pm UTC](https://www.ruby-forum.com/t/how-do-you-test-your-rest-api-with-xml/92156/4 "2007-04-16T18:46:13Z")

</div>

This really doesn’t make sense to be available from unit tests. The  
format that is returned is controlled by the controller class, not the  
model, so the proper place to test this is in functional and/or  
integration test.

On Apr 16, 12:40 pm, Jonathan del Strother [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
