groovy
groovy copied to clipboard
GROOVY-8209 simple http client without extra dependecies
The idea is to create a simple http client without extra dependencies that will cover rest client needs.
Code example:
def r = HTTP.get(
url : 'https://www.googleapis.com/customsearch/v1',
query: [ q: 'hello world' ],
headers: [
'Accept':'application/json',
//'Authorization' : ...,
],
//optional - ssl context
ssl : getNaiveSSLContext(),
//optional - receiver
receiver : { stream,context -> new JsonParser().parse(stream) },
//optional - body
)
assert r.response.code == 200
println r.response.body
Hello @paulk-asert , @blackdrag , @melix , groovy team, I'd like to suggest to integrate simple http client class into groovy language. In attachment there is a generated javadoc and asciidoc documents. Waiting for review or any comments.
Thanks for your submission. I am hoping to get time to review shortly.
-1 from me unless it can be made compatible with the upcoming Java 9 native client http://download.java.net/java/jdk9/docs/api/java/net/http/HttpClient.html
My opinion is that something like this would be best provided as an external library and not included (from the start anyway) as part of Groovy itself or one of its subprojects. There are already some nice http libraries such as http-builder-ng and OkHttp that are more complete and widely used. Groovy has added some nice enhancements to the URL class for very basic fetching content, any more in my opinion is really best left to an outside library.
i see. ok, let's close this request.
Isn't the JDK providing HttpClient, HttpRequest and HttpResponse as part of Java 11?
The idea is to simplify code required to perform put/post/... Class created before java11.
closing as per https://github.com/apache/groovy/pull/556#issuecomment-315630564