I'm new to Akka-Http please bear with me.

What I'm trying to do is 

1. Connect to a Restful service
2. Unmarshall the json payload into the following case class structure


case class ColorBlob(url: String, averageColor: String, classificationColor: 
String)
case class ColorBlobsResponse(colorBlobs: Map[String, Option[ColorBlob]])


In theory this should be simple, but it turns out that anything on this 
topic is either outdated or way over my head, as in this article 
http://malaw.ski/2016/04/10/hakk-the-planet-implementing-akka-http-marshallers/.
 


http://doc.akka.io/docs/akka-http/10.0.1/scala/http/common/unmarshalling.html 
doesn't explain how to actually write an unmarshaller

This is where I got so far:

Issuing the request

val request = HttpRequest(method = HttpMethods.GET, uri = 
s"https://colorblobs.service.net/ws/colorblobs/en?productCodes=904655";)

val future = Http().singleRequest(request)
val result: ColorBlobsResponse = 
Await.result(future.flatMap(Unmarshal(_).to[ColorBlobsResponse]), Duration.Inf)



Providing the  unmarshaller. This is also where I got stuck

object ColorBlobJsonProtocol extends DefaultJsonProtocol {
  implicit val colorBlobsUnmarshaller = new 
FromResponseUnmarshaller[ColorBlobsResponse] {
    implicit val colorBlobsFormat = jsonFormat1(ColorBlobsResponse)
    def apply(response: HttpResponse) = try {
      val entity: ResponseEntity = response.entity
??????

    }
  }
}



Now that I have ResponseEntity what would be the next step?

Maybe there is a blog article explaining what  jsonFormat1, 
DefaultJsonProtocol and FromResponseUnmarshaller actually do?

 I'm using akka-http 10.0.5 btw.


Thanks a lot!



-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to