我正在尝试使用 Lift 进行休息服务,当我尝试传递 json 正文时遇到问题。
模型:
case class TestData(substore:String) {}
object TestData {
private implicit val formats = net.liftweb.json.DefaultFormats
implicit def toJson(item: TestData): JValue = Extraction.decompose(item)
def apply(in: JValue): Box[TestData] = Helpers.tryo{in.extract[TestData]}
def unapply(in: Any): Option[TestData] = in match {
case i: TestData => Some(TestData(i.substore)
case _ => None
}
}
休息:
object RestExample extends RestHelper {
serve {
case "api" :: "user" :: AsLong(id) :: Nil JsonGet _ => JInt(id)
case "api" :: "test2" :: Nil JsonPut _ => TestData("testeee"): JValue
case "api" :: "test" :: Nil JsonPut TestData(testData) -> _ => testData : JValue
}
}
简单的 put 测试有效:
curl -i -H "Content-Type: application/json" -X PUT http://localhost:8080/api/test2
但是我无法使用 json 主体进行测试:
curl -i -H "Content-Type: application/json" -X PUT -d '{"substore":"abs"}' http://localhost:8080/api/test
在这种情况下,我总是收到:
<html> <body>The Requested URL /api/test was not found on this server</body> </html>