I am playing with Akka Http client side. I have created a simple request but how can I unmarshal the respose? in the server side it is easy to use circe to marshal the response, but I have difficulties in the client side
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.Uri.Query
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.Materializer
import scala.concurrent.ExecutionContext
class QuestionsFetcher {
import de.heikoseeberger.akkahttpcirce.CirceSupport._
import io.circe.generic.auto._
val baseUrl = "https://somewhere.com"
def fetch(tag: String)(implicit ac: ActorSystem, materializer: Materializer) = {
implicit val ec: ExecutionContext = ac.dispatcher
val fromDate = DateTime.now.minus(1000 * 60 * 60 * 24)
val uri = Uri(baseUrl).withQuery(Query("order"->"desc"))
val request = HttpRequest(HttpMethods.GET, uri)
Http().singleRequest(request)
.map(r => Unmarshal(r.entity.withContentType(ContentTypes.`application/json`)).to[Items])
} }
When running the code I am getting ErrorFuture(io.circe.ParsingFailure: expected json value got (line 1, column 1))
Encoder[Items]
in the same scope? – Travis Brown