The new Gigahorse 0.1.0 page states that it is “an HTTP client for Scala with Async Http Client underneath.”
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 15.11, “How to send JSON POST data to a REST URL.”
When writing Scala code, you want to send JSON data (or other data) to a
POST URL, either from a standalone client, or when using a framework that doesn’t provide this type of service.
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:
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:
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:
After writing a Java REST (RESTful) client using Apache HttpClient, I turned around and modified that code to be a Scala REST client, also using the Apache HttpClient library.
PHP OpenSSO FAQ: Can you share a PHP script to manually authenticate OpenSSO users during a login process?