web-servicesscalarestplayframework-2.0http-post

How to http post with an empty body request using WS API in Playframework 2 / Scala?


I try to send an HTTP POST request to a service endpoint using Play2/Scala WS API. Since there is no parameters to be sent in the HTTP POST body, how can I send it using

WS.url("http://service/endpoint").post()

I have tried post() without argument but it gave me an error.

Cannot write an instance of Unit to HTTP response. Try to define a Writeable[Unit]

Can you please help on this ?

thanks in advance...


Solution

  • Since post awaits a value that implements the Writeable and ContentTypeOf type classes, you can use the Results.EmptyContent from play.api.mvc. (See API)

    So I guess

    WS.url("http://service/endpoint").post(Results.EmptyContent())
    

    should do. (Didnt test)