1
votes

I'm trying to post to a service using Spray

var authenticationPipeline: HttpRequest => Future[Authentication] = sendReceive ~> unmarshal[Authentication]

I have a pipeline setup, that is expecting to return a type of Authentication (a case class) and unmarshal this. Pretty straight forward.

When constructing requests, I attempt to use to following pattern.

val fD = FormData(Seq(
    "grant_type" -> "authorization_code",
    "code" -> authorisation_code,
    "redirect_uri" -> "http://www.example.com",
    "client_id" -> apiClientId,
    "client_secret" -> apiClientSecretKey
))

I'm then sending this like so.

authenticationPipeline(Post(oauthUrl, fD))

The issue is that the service I'm posting to is returning an unsupported media type error, and upon further inspection it looks like the http enitity's media/content type is json and the content is a json string.

I've got around this issue by using URLEncode and posting this raw string by manually constructing a HTTP request, the issue is now I'm running into issue with encoding and it's just not very clean code. I guess I'm just unsure why this is happening almost implicitly.

The following links influenced how I set this up but don't mention similar issues, https://groups.google.com/forum/#!topic/spray-user/JjA2LCLfib8 & Posting application/x-www-form-urlencoded using spray

Any pointers on what I could be doing wrong would be appreciated. Please let me know if I've omitted any essential information.

Thanks in advance!

1

1 Answers

0
votes

By testing my code in isolation I was able to determine that one of my imports was bringing in an implicit JSON marshaller. By being more specific with my imports I was able to surmount this problem. Hope this helps someone in the future!