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.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 15.10, “How to create a Twitter client in Scala.”
You want to create a client to connect to Twitter to access the information you want, such as showing timelines and trends.
I just got back into using an Android
AsyncTask, and it took me a little while to re-load the concepts in my head. I used
AsyncTask’s a few years ago, but haven’t used them since.
To help remember how they work, I created a little
AsyncTask example project, and I’ve included all of the source code for that project here. I’ll show all of the source code for my classes and configuration files, and then explain the code at the end.
When you first work with a Sencha ExtJS or Touch Store and Proxy, you’ll quickly find that when you create GET and POST REST services, by default the store/proxy adds extra parameters to the end of the URLs you’re accessing.
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:
I don't get to parse too much JSON code with Java because the biggest JSON source I work with is Twitter, and I always use the Twitter4J project to interact with their web services. But a few days ago while working on an Android project, I just wanted to access their "Twitter Trends" REST service, and I used Java and the json.org Java library that comes with Android to parse the Twitter Trends JSON feed like this:
As quick post here today, if you need a Scala REST client function, the following source code should be able to work for you, or at least be a good starting point. I’ve been using it in several applications today, and the only thing I think it needs is the ability to set a connection timeout and socket timeout, and I share the code for that down below.
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.