OkHttp – An HTTP & SPDY Java client

OkHttp

                               As HTTP/2 adoption is already done by some of the web servers and the browsers, its 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 a single TCP socket for all the requests.
  • Supports for both synchronous blocking and asynchronous nonblocking 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 for 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.

Download From GitHub

Siva Janapati is an Architect with experience in building Cloud Native Microservices architectures, Reactive Systems, Large scale distributed systems, and Serverless Systems. Siva has hands-on in architecture, design, and implementation of scalable systems using Cloud, Java, Go lang, Apache Kafka, Apache Solr, Spring, Spring Boot, Lightbend reactive tech stack, APIGEE edge & on-premise and other open-source, proprietary technologies. Expertise working with and building RESTful, GraphQL APIs. He has successfully delivered multiple applications in retail, telco, and financial services domains. He manages the GitHub(https://github.com/2013techsmarts) where he put the source code of his work related to his blog posts.

Tagged with: ,
Posted in Frameworks, General

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

DZone

DZone MVB

Java Code Geeks
Java Code Geeks
%d bloggers like this: