restful

Using curl scripts to test RESTful web services

There may be better ways to do this, but as I’m writing a mobile app with the client written in Sencha Touch, and the server written with the Play Framework, I’ve written some curl scripts to simulate GET, POST, DELETE, and PUT request (method) calls to my RESTful Play services.

The following examples show the code for each of these scripts. First, here’s get.sh:

How to load an XML URL in Scala (contents of an XML web page)

Scala XML FAQ: How do I load an XML URL in Scala? (How do I read/download the contents of an XML URL in Scala?)

To load the contents of an XML URL (web page) in Scala, such as an RSS news feed or RESTful web service, just use the load method of the Scala XML class:

val xml = XML.load("http://www.devdaily.com/rss.xml")

Here's an example of what this looks like in the Scala REPL:

A Scala JSON (Gson) HTTP POST RESTful client example

While working on a Scala project recently I created the following example Scala code to test a variety of things, including:

  • Scala case classes
  • The Apache HttpClient classes, including HttpPost
  • Creating JSON with Gson
  • Sending the JSON object/string to my POST RESTful server

Given that brief introduction, here's the source code for my Scala HTTP client, which uses POST (Apache HttpPost) to send data to a RESTful web service:

Syndicate content