Entity directive doesn't support PUT?

When I do in my code

put {
pathEnd {
entity(as[ApplicationDB]) { updatedApplication =>
complete(updatedApplication)
}
}
}

I get 405 Method Not Allowed error
But if I do just

put {
pathEnd {
complete(“Ok”)
}
}

It works. What can be the cause of the problem? Really want to use PUT

Hi Sergeda,

I think the problem might rely on the (un)marshaller not being present or maybe just that the call you are using to test doesn’t include the Content-Type header. I’ve tested it with the following snippet and it works:

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.server.{ HttpApp, Route }
import spray.json.DefaultJsonProtocol

case class Person(name: String, favoriteNumber: Int)
object PersonJsonSupport extends DefaultJsonProtocol with SprayJsonSupport {
  implicit val PortofolioFormats = jsonFormat2(Person)
}

import PersonJsonSupport._

class Putt extends HttpApp {
  override protected def routes: Route = put {
    pathEndOrSingleSlash {
      entity(as[Person]) { person =>
        complete(s"-$person-")
      }
    }
  }
}

object Putt extends App {

  new Putt().startServer("localhost", 8888)
}
$>curl -XPUT localhost:8888/ -H "Content-Type: application/json" -d '{ "name": "Jane", "favoriteNumber" : 42 }'
-Person(Jane,42)-% 
1 Like

Thanks. You was right. It was issue with marshaller

Cool! You’re welcome!