Testing Rails RESTful Web Services with curl
- 0
- Add a Comment
Today I found the need to test out some RoR RESTful based web services. I figured I could A. write a quick client app or B. find some tool to do it for me. Doing a Mr. Google search I ran across a this post by Derek Brooks doing just what i was looking for. He uses curl to test web services so I just followed his procedure and basically came up with the following.
# and -H to set the Accept Header and Content type
GET
> curl -X GET http://localhost:3000/locations
or
> curl -X GET http://localhost:3000/locations/1
DELETE
> curl -X DELETE http://localhost:3000/locations/1
PUT (note the lack of -X since put is default)
> curl -H "Accept: text/xml" -H "Content-type: application/xml" -d "<?xml version =’1.0′ encoding ‘UTF-8′?><location><abbreviation>AVC</abbreviation><city>Lancaster</city><country>USA</country></location>" http://localhost:3000/locations/1
POST
> curl -X POST -H "Accept: text/xml" -H "Content-type: application/xml" -d "<?xml version =’1.0′ encoding ‘UTF-8′?><location><abbreviation>AVC</abbreviation><city>Lancaster</city><country>USA</country></location>" http://localhost:3000/locations/1