An endpoint in Akka Http looks like this:
pathPrefix("somePath" / Segment) { someData =>
post {
entity(as[SMS]) { sms =>
// some code here ...
complete(StatusCodes.OK)
}
}
}
And SMS is defined as:
sealed trait Message
case class SMS(numFrom: String, message:String) extends Message
case class Email(emailFrom: String, message: String) extends Message
If I want to receive a list of SMS
I can do the following:
type SMSList = List[SMS]
...
pathPrefix("somePath" / Segment) { someData =>
post {
entity(as[SMSList]) { listOfSMSs =>
// some code here ...
complete(StatusCodes.OK)
}
}
}
What if I want to receive a list of SMSs and Emails at the same time? I've tried this and it didn't work:
type MessageList = List[Message]
pathPrefix("somePath" / Segment) { someData =>
post {
entity(as[MessageList]) { listOfMessages =>
// some code here ...
complete(StatusCodes.OK)
}
}
}
Is it possible to receive a list of objects that belongs to the same hierarchy?
Libraries:
circe = 0.13.0
heikoseeberger = 1.35.3
akka http = 10.2.3
Json:
[
{"numForm": "123 456", "message": "sms message"},
{"emailFrom": "some@mail.com", "email message"}
]