I am trying to create HttpRequest and try to submit json to endPoint , My rest services are written using akka-http
case class JobInfo(jobName: String,
appId: Option[String] = None,
status: Option[String] = None,
modify_date: Option[Long] = None)
object Test extends App{
import HttpMethods._
val fieldList = List(
("jobName",Json.fromString("TestJobA")),
("appId",Json.fromString("1234")),
("status",Json.fromString("Running")),
("modify_date",Json.fromLong(DateTime.now.getMillis))
)
val json = Json.fromFields(fieldList)
val endPoint = Uri.from(scheme = "http",
host = "0.0.0.0",
port = 7000,
path = s"/updateJobDetails/").toString()
val requestEntity = HttpEntity(MediaTypes.`application/json`, json.toString)
// val postRequest1 = HttpRequest.POST("/receive").withEntity(requestEntity)
HttpRequest(POST,"http://0.0.0.0:7000/updateJobDetails",entity = requestEntity)
}
But this doesnot seem to work, Earlier I used spray to do the same as
val pipe: HttpRequest => Future[HttpResponse] = sendReceive
val json =
s"""{
| "jobName" : "jobA",
| "appId" :"${jobInfo.appId.getOrElse("Not Set")}",
| "status" :"${jobInfo.status.getOrElse("Not Set")}",
| "modify_date" :${DateTime.now.getMillis}
|}""".stripMargin.parseJson.asJsObject()
//Rest EndPoint for JobDetails updation.
val endPoint = Uri.from(scheme = "http",
host ="0.0.0.0",
port = 7000,
path = s"/updateJobDetails").toString()
val response = pipe(Put(endPoint, json))
Can anyone help me correcting the what I am missing