Curl in to RESTful posters

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: