Giter Site home page Giter Site logo

king-http-client's Introduction

king-http-client

Api

First off the HttpClient needs to be created and started. To make it easier, use the NettyHttpClientBuilder. Use the different set methods on the NettyHttpClientBuilder to tweak how HttpClient works.

NettyHttpClientBuilder nettyHttpClientBuilder = new NettyHttpClientBuilder();
NettyHttpClint httpClient = nettyHttpClientBuilder.createHttpClient();
httpClient.start();

Before start is called, httpClient.setConf can be used to tweak internal settings of the client.

Then to use it, use the fluent method builder on the HttpClient:

Future<FutureResult<String>> resultFuture = httpClient.createGet("http://some.url").build().execute();
httpClient.createPost("http://someUrl").content("someContentToBePosted".getBytes()).withQueryParameter("param1", "value1").withHeader("header1", "headerValue1").build().execute();

Or using callback objects:

httpClient.createGet("http://some.url").build().execute(new StringHttpCallback() {
            @Override
            public void onCompleted(HttpResponse<String> httpResponse) {

            }

            @Override
            public void onError(Throwable throwable) {

            }
        });

For more complex cases or when the result is unfit to handle as a string, a ResponseBodyConsumer can be defined in the HttpCallback object:

httpClient.createGet("http://some.url").build().execute(new HttpCallback<Void>() {
            @Override
            public void onCompleted(HttpResponse<Void> httpResponse) {

            }

            @Override
            public ResponseBodyConsumer<Void> newResponseBodyConsumer() {
                return new ResponseBodyConsumer<Void>() {
                    @Override
                    public void onBodyStart(String contentType, String charset, long contentLength) throws Exception {

                    }

                    @Override
                    public void onReceivedContentPart(ByteBuffer buffer) throws Exception {

                    }

                    @Override
                    public void onCompletedBody() throws Exception {

                    }

                    @Override
                    public Void getBody() {
                        return null;
                    }
                };
            }

            @Override
            public void onError(Throwable throwable) {

            }
        });

Thread model

The methods on HttpCallback are called by HttpCallbackExecutor, there can therefore be long running jobs in the callbacks. The methods on NioCallback are called by the internal nio threads, they should therefore not be blocking or long running. The same goes for the ResponseBodyConsumer and MetricCallback interfaces.

Limitations

Does not support complex authentication (basic should work using the headers). Does not support proxys. Does not support http2 (yet).

king-http-client's People

Contributors

magnus-gustafsson avatar hrhdreas avatar aghiuru avatar bysse avatar greg-chrystall avatar tulionaja avatar

Watchers

James Cloos avatar Tulio Domingos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.