From the client side of webapp, I ended up on a server route, which is just a wrapper for a third-party API. Using dispatch, I try to make the server-side request the correct header exact and the response of the third-party API to the AJAX client call.
When I do this:
val req = host("third-pary.api.com, 80) val post = req.as("user", "pass") / "route" << Map("key" -> "akey", "val" -> "aval") Http(post > as.String)
I always see a 200 response being returned to an AJAX call (sort of expected). I saw the Either syntax, but I really am Any more, as this is just the exact answer and the title. How will it be written?
I should mention that I use Scalatra on the server side, so the local route:
post("/route") { }
EDIT:
Here is a suggested example of the match I'm playing with, but the match syntax doesn't make sense - I don't care if there is an error, I just want to return it. In addition, I cannot force BODY to return this method.
val asHeaders = as.Response { response => println("BODY: " + response.getResponseBody()) scala.collection.JavaConverters.mapAsScalaMapConverter( response.getHeaders).asScala.toMap.mapValues(_.asScala.toList) } val response: Either[Throwable, Map[String, List[String]]] = Http(post > asHeaders).either() response match { case Left(wrong) => println("Left: " + wrong.getMessage())
Ideally, solutions return a Scalatra ActionResult(responseStatus(status, reason), body, headers) .
user375566
source share