freshwood / akka-http-rest-client   0.2.0

MIT License GitHub

A simple and ready to use akka http client for building HTTP requests and processing responses with custom response handlers

Scala versions: 2.12

akka-http-rest-client

A simple and ready to use akka http client for building HTTP requests and processing responses with custom response handlers

Build Status

akka-http-rest-client is based on the Akka HTTP architecture. The goal is to have an easy to use REST client, which can be used in almost any Scala project

Features

  • Easy using like Spring Rest Templates
  • Builder style for a simple request building
  • Almost all http methods available
  • Default response processor support
  • Functionality to un marshall responses with a given un marshaller (less code for you)
  • Development was focused on JSON support
  • Compression support for deflate / gzip responses

Documentation

https://freshwood.github.io/akka-http-rest-client/

Installation

// All releases are published to bintray
resolvers += Resolver.bintrayRepo("freshwood", "maven")

libraryDependencies ++= List(
  "net.softler" %% "akka-http-rest-client" % "0.2.1"
)

(ammonite)

interp.repositories() ++= Seq(coursier.MavenRepository("https://dl.bintray.com/freshwood/maven/"))

import $ivy.`net.softler::akka-http-rest-client:0.2.1`

Usage

Simple as hell

// When you have an unmarshaller available: (e.g: RootJsonFormat[User])
val result: Future[User] = ClientRequest("http://test.de/1").withJson.get[User]

// Or you just maka a call...
val result: Future[ClientResponse] = testRequest.get()

// Now you can process the response with the inline processor
// The future will fail when an error occurs
val processed: Future[ResponseEntity] = result map(_.process)

// Or you just handle the response by your own
val original: Future[HttpResponse] = result.map(_.response)

Handle (Gzip, Deflate) responses

// Just a request on a API with GZIP responses
val result: Future[ClientResponse] = encodedRequest.withText.get()

// Just map over the entire response an encoder to get your desired object 
val string = result.map(_.decode).flatMap(_.as[String])

Contribution

It would be a pleasure to see a nice contribution. Just add a PR (Pull Request) Or you add an issue with an corresponding PR.

License

This code is open source software licensed under the MIT License