Curl in to RESTful posters

November 16, 2010

Continuing with the theme of integrating Wonderland into the wider web, I recently added a RESTful interface to the Web-based Poster Manager module in the modules warehouse. Now, instead of editing the posters from the web admin interface, authenticated users can also use curl (or wget) to view, edit and delete posters.

In the video below, I provide a brief demo of using the RESTful interface using curl.

The curl commands used are as follows (ignore the line breaks):

To authenticate, and store the cookie (assuming a user name and password of ‘admin’, and a server running on localhost):

curl --cookie-jar cookies.txt --data "username=admin&password=admin"
'http://localhost:8080/security-session-auth/security-session-auth/login?action=login'

To view the list of posters as HTML:

curl --cookie cookies.txt --header "Accept: text/html"
http://localhost:8080/postercontrol/postercontrol/
resources/posters/

To view the list of posters as XML:

curl --cookie cookies.txt --header "Accept: application/xml"
http://localhost:8080/postercontrol/postercontrol/
resources/posters/

To view the first (zero-th) poster as XML:

curl --cookie cookies.txt --header "Accept: application/xml"
http://localhost:8080/postercontrol/postercontrol/
resources/posters/0

To change the contents of the first (zero-th) poster:

curl -X PUT --cookie cookies.txt --header "Accept: application/xml" --header "Content-type:text/plain"
--data "Updated Poster"
http://localhost:8080/postercontrol/postercontrol/
resources/posters/0

To delete the first (zero-th) poster:

curl -X DELETE --cookie cookies.txt --header
"Accept: application/xml" http://localhost:8080/postercontrol/postercontrol/
resources/posters/0

Many thanks to Jon Kaplan for his guidance on authentication.


Follow

Get every new post delivered to your Inbox.

Join 54 other followers

%d bloggers like this: