Testing Rails RESTful Web Services with curl

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.

#Note the -X arg that specifies what HTTP method to use
# 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

Simple LDAP authentication with Ruby

This is the super simple way I have done LDAP authentication with rails.  Basically I am just checking to see if ldap will bind with the username and password.  Also I am checking to see if that user exists.

def authenticate
  authenticate_or_request_with_http_basic do |username, password|
   ldap = Net::LDAP.new :host => ‘ldap.host.com’, :base => ‘ou=active, ou=employees, ou=people, o=host.com’
   ldap.auth ‘uid=’ + username + ‘,ou=active,ou=employees,ou=people,o=host.com’, password
   if ldap.bind
    @point_person = PointPerson.find_by_username(username)
    if !@point_person.nil?
     return true
    end
   else
    return false
   end
  end
 end

James Gosling today at work

Was an interesting work day today.  James Gosling of Java fame gave a lecture about all things Java and also told some great stories about his life.  I think what I found interesting was his talk on the Brazilian healthcare systems infrastructure.  The whole system being written in Java, pretty amazing.  It made me wonder, I believe President Obama’s healthcare plan includes upgrading the American health care IT infrastucture.  Would sometthing similar to Brazils system be put into place?

Recent Photos

My Videos

Categories