Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

OkHttp – An HTTP and SPDY Java Client

DZone's Guide to

OkHttp – An HTTP and SPDY Java Client

HTTP/2 has seen widespread atoption. OkHttp is a Java Client with HTTP/2 support. Here's an example of HTTP with the SPDY Java client.

Free Resource

Build APIs from SQL and NoSQL or Salesforce data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.

As HTTP/2 adoption is already done by some of the web servers and the browsers, it's time for developers to adopt HTTP client libraries to support HTTP/2. I came across“OkHttp” Java client with HTTP/2 support.

OkHttp supports by default,

  • Uses single TCP socket for all the requests.
  • Supports for both synchronous blocking and asynchronous non-blocking calls.
  • Silently handles the common connection problems. If the services hosted in multiple IP addresses, OkHttp client checks for other alternate IP addresses if the first address fails to respond.

Here we will see an example of GET request and POST request.

OkHttp Client GET Request













Now we will see POST request.

OkHttp POST Request













The source code created for the above example is available on GitHub.

The Integration Zone is brought to you in partnership with CA Technologies.  Use CA Live API Creator to quickly create complete application backends, with secure APIs and robust application logic, in an easy to use interface.

Topics:
okhttp ,http 2

Published at DZone with permission of Siva Prasad Rao Janapati, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}