Knows Not Much Knows Not Much - 12 days ago 6
Scala Question

https4s how to make a POST call to a REST web service

I am trying to use the http4s library. I am trying to make a POST request to a REST web service with some json payload.

when I read the documentation http://http4s.org/docs/0.15/ I can only see a GET method example.

does anyone know how to make a POST?

Answer

It looks like the get/getAs methods mentioned in the example are just convenience wrappers for the fetch method. See https://github.com/http4s/http4s/blob/a4b52b042338ab35d89d260e0bcb39ccec1f1947/client/src/main/scala/org/http4s/client/Client.scala#L116

Use the Request constructor and pass Method.POST as the method.

fetch(Request(Method.POST, uri))