Git Product home page Git Product logo

http-client's Introduction

Maven build PDD status License

Artipie HTTP client implementation.

To install add this dependency to pom.xml file:

<dependency>
  <groupId>com.artipie</groupId>
  <artifactId>http-client</artifactId>
  <version><!-- use latest version --></version>
</dependency>

Artipie HTTP module provides HTTP abstractions. Client module targeted to implement HTTP client on top of these abstractions.

  • ClientSlice - is a Slice that sends request to remote TCP endpoint and returns Response. In that sense it is similar to an HTTP connection.
  • ClientSlices - collection of slices that pools resources and builds ClientSlice by specified protocol (HTTP or HTTPS), host and port.

ClientSlices is entry point for usage of this module:

ClientSlices slices = new JettyClientSlices();
Slice slice = slices.https("artipie.com");
Response response = slice.request(
  "GET /index.html HTTP/1.1",
  Headers.EMPTY,
  Content.EMPTY
);
response.send(
  (status, headers, body) -> {
    // handle recieved data
  }
);

Create client for URI

It is common and convenient to specify a target for HTTP client using URI, as it combines protocol, host and port in one string. URI may also contain non-empty path, so it will be prepended to every HTTP request sent to remote endpoint. UriClientSlice may be used to create client Slice from URI in the following way:

ClientSlices slices = new JettyClientSlices();
Slice slice = new UriClientSlice(
  slices,
  new URI("https://central.artipie.com:54321/my-repo")
);

Authentication

Target endpoint may require authentication over HTTP protocol. AuthClientSlice performs authentication automatically using provided Authenticator instance. Different Authenticator instances may support different authentication schemes such as Basic, Bearer, Digest etc. GenericAuthenticator performs authentication using scheme requested by target server using specified username and password. To enable authentication support using all supported authentication schemes wrap Slice into AuthClientSlice and supply it with GenericAuthenticator:

Slice slice = ...;
Slice authenticated = new AuthClientSlice(
  slice,
  new GenericAuthenticator("username", "password")
);

How to contribute

Fork repository, make changes, send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

$ mvn clean install -Pqulice

To avoid build errors use Maven 3.3+.

http-client's People

Contributors

dependabot-preview[bot] avatar g4s8 avatar genryxy avatar olegmoz avatar olenagerasimova avatar yegor256 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.