All Projects → square → Okhttp

square / Okhttp

Licence: apache-2.0
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects
shell
77523 projects

Projects that are alternatives of or similar to Okhttp

connor
A commandline tool for resetting Kafka Connect source connector offsets.
Stars: ✭ 17 (-99.96%)
Mutual labels:  graalvm
ScriptableMC-Engine
Create TypeScript/JavaScript plugins for Minecraft 1.16 Bukkit/Spigot/Paper
Stars: ✭ 36 (-99.91%)
Mutual labels:  graalvm
ipolyglot
A polyglot kernel for Jupyter notebooks based on GraalVM.
Stars: ✭ 59 (-99.86%)
Mutual labels:  graalvm
netty-native-demo
Instant Netty startup using GraalVM's Native Image Generation
Stars: ✭ 58 (-99.86%)
Mutual labels:  graalvm
quarkus-performance
Comparing the CPU/Memory utilisation - Quarkus via GraalVM Native Image vs. Quarkus via Java Runtime vs. Payara-Micro via Java Runtime.
Stars: ✭ 49 (-99.88%)
Mutual labels:  graalvm
lucene-grep
Grep-like utility based on Lucene Monitor compiled with GraalVM native-image
Stars: ✭ 160 (-99.61%)
Mutual labels:  graalvm
dad
Small configuration management tool for Clojure
Stars: ✭ 122 (-99.7%)
Mutual labels:  graalvm
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (-92.04%)
Mutual labels:  graalvm
yona
Yona is a modern take on a dynamic general-purpose programming language with advanced functional programming, minimalistic ML-like syntax, strict evaluation, for GraalVM polyglot virtual machine (VM).
Stars: ✭ 113 (-99.73%)
Mutual labels:  graalvm
spring-cloud-stream-event-sourcing-testcontainers
Goal: create a Spring Boot application that handles users using Event Sourcing. So, whenever a user is created, updated, or deleted, an event informing this change is sent to Kafka. Also, we will implement another application that listens to those events and saves them in Cassandra. Finally, we will use Testcontainers for integration testing.
Stars: ✭ 16 (-99.96%)
Mutual labels:  graalvm
LogoRRR
A log viewer which visualises log events such that it is easy to identify problems or events of interest. This app was implemented using Scala and JavaFX, GluonHQ toolchain and GraalVM as platform.
Stars: ✭ 40 (-99.9%)
Mutual labels:  graalvm
graalvm
A Cloud Native Buildpack that provides the GraalVM implementations of JREs and JDKs
Stars: ✭ 21 (-99.95%)
Mutual labels:  graalvm
http4s-graal
An experiment running http4s as native image with Graal (+ Substrate)
Stars: ✭ 27 (-99.93%)
Mutual labels:  graalvm
native-java-examples
Native Java Apps with Micronaut, Quarkus, and Spring Boot
Stars: ✭ 44 (-99.89%)
Mutual labels:  graalvm
kotlin-graalvm-custom-runtime-demo
Demo for a AWS Lambda functions written in Kotlin using GraalVM and custom runtimes
Stars: ✭ 23 (-99.94%)
Mutual labels:  graalvm
native-build-tools
Native-image plugins for various build tools
Stars: ✭ 168 (-99.59%)
Mutual labels:  graalvm
azure-native-spring-function
Tutorial on running Spring Boot + GraalVM native images on Azure Functions
Stars: ✭ 56 (-99.86%)
Mutual labels:  graalvm
Enso
Hybrid visual and textual functional programming.
Stars: ✭ 5,238 (-87.32%)
Mutual labels:  graalvm
microprofile.training
home of http://microprofile.training sample app
Stars: ✭ 19 (-99.95%)
Mutual labels:  graalvm
kotlin-graalvm-custom-aws-lambda-runtime-talk
This is the demo code for a talk on improving cold startup times for JVM-based lambdas using GraalVM and Custom AWS Lambda Runtimes.
Stars: ✭ 24 (-99.94%)
Mutual labels:  graalvm

OkHttp

See the project website for documentation and APIs.

HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth.

OkHttp is an HTTP client that’s efficient by default:

  • HTTP/2 support allows all requests to the same host to share a socket.
  • Connection pooling reduces request latency (if HTTP/2 isn’t available).
  • Transparent GZIP shrinks download sizes.
  • Response caching avoids the network completely for repeat requests.

OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. If your service has multiple IP addresses, OkHttp will attempt alternate addresses if the first connect fails. This is necessary for IPv4+IPv6 and services hosted in redundant data centers. OkHttp supports modern TLS features (TLS 1.3, ALPN, certificate pinning). It can be configured to fall back for broad connectivity.

Using OkHttp is easy. Its request/response API is designed with fluent builders and immutability. It supports both synchronous blocking calls and async calls with callbacks.

Get a URL

This program downloads a URL and prints its contents as a string. Full source.

OkHttpClient client = new OkHttpClient();

String run(String url) throws IOException {
  Request request = new Request.Builder()
      .url(url)
      .build();

  try (Response response = client.newCall(request).execute()) {
    return response.body().string();
  }
}

Post to a Server

This program posts data to a service. Full source.

public static final MediaType JSON
    = MediaType.get("application/json; charset=utf-8");

OkHttpClient client = new OkHttpClient();

String post(String url, String json) throws IOException {
  RequestBody body = RequestBody.create(json, JSON);
  Request request = new Request.Builder()
      .url(url)
      .post(body)
      .build();
  try (Response response = client.newCall(request).execute()) {
    return response.body().string();
  }
}

Further examples are on the OkHttp Recipes page.

Requirements

OkHttp works on Android 5.0+ (API level 21+) and Java 8+.

OkHttp depends on Okio for high-performance I/O and the Kotlin standard library. Both are small libraries with strong backward-compatibility.

We highly recommend you keep OkHttp up-to-date. As with auto-updating web browsers, staying current with HTTPS clients is an important defense against potential security problems. We track the dynamic TLS ecosystem and adjust OkHttp to improve connectivity and security.

OkHttp uses your platform's built-in TLS implementation. On Java platforms OkHttp also supports Conscrypt, which integrates BoringSSL with Java. OkHttp will use Conscrypt if it is the first security provider:

Security.insertProviderAt(Conscrypt.newProvider(), 1);

The OkHttp 3.12.x branch supports Android 2.3+ (API level 9+) and Java 7+. These platforms lack support for TLS 1.2 and should not be used. But because upgrading is difficult, we will backport critical fixes to the 3.12.x branch through December 31, 2021.

Releases

Our change log has release history.

The latest release is available on Maven Central.

implementation("com.squareup.okhttp3:okhttp:4.9.3")

Snapshot builds are available. R8 and ProGuard rules are available.

Also, we have a bill of materials (BOM) available to help you keep OkHttp artifacts up to date and be sure about version compatibility.

    dependencies {
       // define a BOM and its version
       implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.3"))

       // define any required OkHttp artifacts without version
       implementation("com.squareup.okhttp3:okhttp")
       implementation("com.squareup.okhttp3:logging-interceptor")
    }

MockWebServer

OkHttp includes a library for testing HTTP, HTTPS, and HTTP/2 clients.

The latest release is available on Maven Central.

testImplementation("com.squareup.okhttp3:mockwebserver:4.9.3")

GraalVM Native Image

Building your native images with Graal https://www.graalvm.org/ should work automatically. This is not currently in a final released version, so 5.0.0-alpha.2 should be used. Please report any bugs or workarounds you find.

See the okcurl module for an example build.

$ ./gradlew okcurl:nativeImage
$ ./okcurl/build/graal/okcurl https://httpbin.org/get

License

Copyright 2019 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].