groovy icon indicating copy to clipboard operation
groovy copied to clipboard

GROOVY-8209 simple http client without extra dependecies

Open dlukyanov opened this issue 8 years ago • 7 comments

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

dlukyanov avatar Jun 01 '17 10:06 dlukyanov

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.

groovydoc_http.zip

dlukyanov avatar Jun 12 '17 12:06 dlukyanov

Thanks for your submission. I am hoping to get time to review shortly.

paulk-asert avatar Jun 19 '17 12:06 paulk-asert

-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

graemerocher avatar Jun 19 '17 13:06 graemerocher

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.

jwagenleitner avatar Jul 16 '17 18:07 jwagenleitner

i see. ok, let's close this request.

dlukyanov avatar Jul 16 '17 19:07 dlukyanov

Isn't the JDK providing HttpClient, HttpRequest and HttpResponse as part of Java 11?

eric-milles avatar Nov 13 '19 15:11 eric-milles

The idea is to simplify code required to perform put/post/... Class created before java11.

dlukyanov avatar Nov 13 '19 19:11 dlukyanov

closing as per https://github.com/apache/groovy/pull/556#issuecomment-315630564

blackdrag avatar Aug 16 '23 19:08 blackdrag