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 <https://github.com/hseeberger/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

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to