Hi, I am doing my first steps with Akka HTTP with no previous experience with Spray. I need to implement a POST that can accept either
text/plain or
application/json and returns
application/json. I am using
akka-http-json library for marshalling/unmarshalling json.
This is the part of the route that deals with it:
path("things") {
post {
decodeRequest {
request.entity.contentType.mediaType match {
case MediaTypes.`text/plain` =>
import PredefinedFromEntityUnmarshallers.stringUnmarshaller
entity(as[String]) { body => // Every line can contain things, empty lines or comments
complete {
Source.fromString(body).getLines
.map(_.trim)
.filterNot(line => line.isEmpty || line.startsWith("#"))
.toSeq
}
}
case MediaTypes.`application/json` =>
entity(as[List[Thing]]) { things =>
complete(things.map(_.name))
}
case _ =>
reject
}
}
}
}When I do a request with curl with '
Content-Type:text/csv' for example I get a:
HTTP/1.1 404 Not Found
The requested resource could not be found.
My gut intuition tells me that I am not doing the media type multiplexing the right way. What is the idiomatic way to handle different media types ?, and how can I specify the allowed ContentTypes (or media types) so the response error is more specific ?
Thank you very much,
Christian