I am trying to make a liftweb rest server that accepts POST
requests for a small internal testing and call it through Spring framework's RestTemplate#postForObject("http://localhost:9090/api/validate/", request, String.class);
. I went through Simply liftweb's Chapter 11 REST.
My RestController.scala is
13 object RestController extends RestHelper {
14 val data = LiftRules.loadResourceAsXml("/ValidationReply.xml");
21 serve {
22 case "api" :: "validate" :: _ XmlPost xml -> _ => <system>
26 <id>TEST</id>
27 <name>PILOT</name>
28 <version>1</version>
29 <ip_address>192.168.2.18</ip_address>
30 <connector>
31 <id>UPD</id>
32 </connector>
33 </system>
124 case JsonGet("api" :: "validate" :: _, _) => JString("Validated")
125 }
126 }
When I request the server with postUrl = "http://localhost:9090/api/validate"
, I get the not found error response
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>The Requested URL /api/validate was not found on this server</body>
</html>
When restUrl = "http://localhost:9090/api/validate"
, I get second api called with reply "Validated"
. How do I make the POST
request in liftweb?
What you have is looking for a POST
that is XML. As per the source,
it gets passed through A trait that defines the TestPost extractor. Is the request a POST, has JSON or XML data in the post body and something that expects JSON or XML in the response.
I'm not sure if you are just making the request or if you are actually sending data. But, assuming you are just making a post request, I would try posting XML in the body. Otherwise, you could try rewriting the rule using Post
instead of XmlPost
like:
case Post("api" :: "validate" :: Nil, req) =>
<system>
<id>TEST</id>
<name>PILOT</name>
<version>1</version>
<ip_address>192.168.2.18</ip_address>
<connector>
<id>UPD</id>
</connector>
</system>