Coder Social home page Coder Social logo

freshwood / akka-http-rest-client Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 5.0 38 KB

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

License: MIT License

Scala 100.00%
akka akka-http rest rest-client simple marshaller json

akka-http-rest-client's Introduction

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

akka-http-rest-client's People

Contributors

freshwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

akka-http-rest-client's Issues

Extend documentation

Extend the documentation and more helpful samples.
The docu should contain the following section

  • Definition
  • Installation
  • Usage
  • Http Methods
  • When to use?

tcp idle-timeout

I encounter an error, sth like "tcp idle-timeout, no bytes pass in last 1 minutes"
I'd like to change it to 3 minutes.
How do I do it using the library?

Or just set the below property in configuration file?
akka.http.client.idle-timeout

Thanks!

how to post?

Hi, assume I want to post some data to a rest api

val respEntity: Future[ByteString] = for {
request <- Marshal(postData.getBytes()).to[RequestEntity]
response <- ClientRequest().withJson.uri(uri).post().map(_.response)
entity <- Unmarshal(response.entity).to[ByteString]
} yield entity

where should I put request in post?

thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.