Category Archives: Misc - Page 10

Using cURL to test a REST service

When testing a REST service I tend to use cURL most of the time. It’s fast and pretty easy (when you write down all the options like I have here ;))

POST

curl -i -H "Accept: application/xml" -X POST -d "firstname=niklas&lastname=ottosson" http://127.0.0.1/students/student  

This will create (POST) a new student with firstname ‘niklas’ and lastname ‘ottosson’

PUT

curl -i -H "Accept: application/xml" -X PUT -d "mail=niklas@mailinator.com" http://127.0.0.1/students/student/82  

This will set (PUT) the mail address on student with id number 82

DELETE

curl -i -H "Accept: application/xml" -X DELETE http://127.0.0.1/students/student/82  

This will delete student with id number 82

GET

curl -i -H "Accept: application/xml" -X GET "http://127.0.0.1/students?firstname=niklas&lastname=ottosson"  

This will get us the student were firstname is ‘niklas’ and lastname ‘ottosson’ (quotes are needed for passing multiple parameters)

OPTIONS
-i – tells cURL to display the response header so we can examine it for errors
-H – tells cURL to send request headers. In this example we tell the system that we only want xml formated responses (“Accept: application/xml”)
-X – sets what REST function we want to use
-d “data1=foo&data2=bar” – is the data we want to send/save (only for PUT or POST)

Put sites on different ports with Lighttpd web server

Maybe you want to have your personal www directory/web service/anything on a separate port on your “lighty” web server. This is easily accomplished by just adding a setting to your lighttpd.conf (/etc/lighttpd/lighttpd.conf):

$SERVER["socket"] == ":81" {
        server.document-root        = "/home/user/www"
}

This will redirect all traffic to port 81 to ‘/home/user/www’

To add more ports just create another entry in the lighttpd.conf file

Also make sure your firewall allows traffic on the desired port and that lighttpd has the rights to read you new webroot!

Tested on Debian Lenny (ARM) running on a Linksys NSLU2

Linking parameters from main report to subreports in Crystal Reports XI

This is one of those things I always seems to forget how to do (maybe I’m not doing it often enough :)), even though it is one of the simplest things there is in Crystal Reports:

  1. Open your main report
  2. Go to Edit->Subreport Links…

    Subreport links...

    Subreport Links...

  3. Now just move the parameters in the main report (left side) to the subreport (right side)

    Subreport links window

    Subreport links window

  4. Click “OK” and your done!