Simplified Http
This is a fully featured http client for Scala which wraps java.net.HttpURLConnection
Features:
- Zero dependencies
- Cross compiled for Scala 2.10, 2.11, 2.12, and 2.13-M3
- OAuth v1 request signing
- Automatic support of gzip and deflate encodings from server
- Easy to add querystring or form params. URL encoding is handled for you.
- Multipart file uploads
Non-Features:
- Async execution
- The library is thread safe. HttpRequest and HttpResponse are immutable. So it should be easy to wrap in an execution framework of your choice.
Works in Google AppEngine and Android environments.
Note: 2.x.x is a new major version which is both syntactically and behaviorally different than the 0.x.x version.
Previous version is branched here: https://github.com/scalaj/scalaj-http/tree/0.3.x
Big differences:
- Executing the request always returns a HttpResponse[T] instance that contains the response-code, headers, and body
- Exceptions are no longer thrown for 4xx and 5xx response codes. Yay!
- Http(url) is the starting point for every type of request (post, get, multi, etc)
- You can easily create your own singleton instance to set your own defaults (timeouts, proxies, etc)
- Sends "Accept-Encoding: gzip,deflate" request header and decompresses based on Content-Encoding (configurable)
- Redirects are no longer followed by default. Use .option(HttpOptions.followRedirects(true)) to change.
Installation
in your build.sbt
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.4.1"
maven
<dependency>
<groupId>org.scalaj</groupId>
<artifactId>scalaj-http_${scala.version}</artifactId>
<version>2.4.1</version> </dependency>
If you're including this in some other public library. Do your users a favor and change the fully qualified name so they don't have version conflicts if they're using a different version of this library. The easiest way to do that is just to copy the source into your project :)
Usage
Simple Get
import scalaj.