A suite of scala libraries for building and consuming RESTful web services on top of Akka: lightweight, asynchronous, non-blocking, actor-based, testable
@shankarshastri you can use spray-json.
import spray.json._
val jsonString: String = ???
val json: JsObject = jsonString.parseJson.asJsObject
or you can declare a class describing this json and declare format for it and then convert to it directly:
class JsonRepr(???)
implicit object ReprFormat extends RootJsonFormat[JsonRepr]{
???
}
import spray.json._
val jsonString: String = ???
jsonString.parseJson.convertTo[ReprFormat]
jsonString.parseJson.asJsObject.fields
will return Map[String, JsValue]
concat
instead of ~
which might be less prone to confusing IntelliJ - not sure if that was in Spray already though (https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/index.html)
could not find implicit value for parameter m: akka.http.scaladsl.marshalling.Marshal
ler[eneovim.EnMessage,akka.http.scaladsl.model.ws.Message]
[error] val outgoing = Source.fromFuture(Marshal(myMsg).to[Message])
[error] ^
HttpEntity
? It works for those because of the implicit conversion at https://github.com/akka/akka-http/blob/master/akka-http-marshallers-scala/akka-http-spray-json/src/main/scala/akka/http/scaladsl/marshallers/sprayjson/SprayJsonSupport.scala#L65, you might want to introduce a similar one for Message
implicit def sprayJsonToWsMessageMarshaller[T](implicit writer: RootJsonWriter[T], printer: JsonPrinter = CompactPrinter): Marshaller[T, Message] =
Marshaller.strict(t => Marshalling.Opaque(() => TextMessage(writer.write(t))))
might work?
Hey I know spray is EOL'd but I'm wondering if there would be any concerns w/ setting a request timeout at a per-request level
httpExtension ! connect
def receive = {
case akka.io.Tcp.Connected(_, _) =>
// The client should then respond with Connected.
// We take the sender of that Connected response (which is an HttpClientConnection)
val httpClientConnection = sender()
sender() ! SetRequestTimeout(timeout.duration)
sender() ! request
case res: HttpResponse =>
// HttpResponse is the expected response from sending the HttpRequest.
promise.success(res)
context.stop(self)
// handle errors
I feel like this may not work
Hi guys! I can't get the JsonFormats for recursive Types section of the README.md compiling. Literally copy pasting
case class Foo(i: Int, foo: Foo)
implicit val fooFormat: JsonFormat[Foo] = lazyFormat(jsonFormat(Foo, "i", "foo"))
leads to
[error] /Users/thomasvogel/sandbox/scala-sandbox/akka-http-sandbox/src/main/scala/tom/vogel/Example.scala:57:68: forward reference extends over definition of value fooFormat
[error] implicit val fooFormat: JsonFormat[Foo] = lazyFormat(jsonFormat(Foo, "i", "foo"))
Any ideas?
jsonFormatRec
derivation macro from the kebs library for that, like here: https://github.com/plokhotnyuk/jsoniter-scala/blob/master/jsoniter-scala-benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/benchmark/SprayFormats.scala#L133