How to use POST in REST/http

#1

Hello,

I have issue about using the REST/Http with GET because in many time my uri go too long and the server response is : 414 uri too long. im wondering if there is any posibility to use the post method if yes how we can do it

#2

Hello @ghassane_elkebir,

I can see different questions here, the HTTP method and the way to provide parameters.

If you use Resty for your REST/Http it will use a GET method when you call the function json with only the URI:

// This will create a GET request with two parameters provided by the URI.
new Resty().json("http://myuri.com?param1=one&param2=two")

If you provide a content to your request, it will use a POST or PUT method:

// This will create a POST request with two parameters provided by the URI.
new Resty().json("http://myuri.com?param1=one&param2=two", Resty.content(""))

If you want to provide the parameters as form-urlencoded then you need to use a FormContent:

// This will create a POST request with two parameters provided as form-urlencoded.
new Resty().json("http://myuri.com",  new FormContent("param1=one&param2=two"))

of course you can mix both:

// This will create a POST request with two parameters provided by the URI and two parameters provided as form-urlencoded.
new Resty().json("http://myuri.com?param1=one&param2=two",  new FormContent("param3=three&param4=four"))

Regards,