How do I create a POST request with form field content with Spray?
Asked Answered
B

1

6

I've got a Spray service that expects a POST with certain form fields filled out. I'm trying to work out how to create an appropriate POST in my test spec in order to test this.

What I have so far

  Post("/customer") ~> sealRoute(myRoute) ~> check {
    responseAs[String] must contain("Success message")
  }

Which does a POST to the /customer route, as expected. How do I add form fields to this?

Biagi answered 24/1, 2014 at 3:26 Comment(0)
M
10

You can use the spray.http.FormData class:

Post("/customer", FormData(Seq("field1"->"value1", "field2"->"value2")) ~>
  sealRoute(myRoute) ~> check {
    responseAs[String] must contain("Success message")
  }
Medora answered 24/1, 2014 at 6:30 Comment(2)
Doesn't compile with could not find implicit value for parameter ta: MyControllerSpec.this.TildeArrow[spray.routing.RequestContext,Unit] Post("/customer", FormData(Seq("field1"->"value1", "field2"->"value2"))) ~> sealRoute(sso.route) ~> check {^Nepos
Post("/", FormData(Map("foo" -> "bar"))) ~> route ~> check works for meDreary

© 2022 - 2024 — McMap. All rights reserved.