A lightweight yet powerful HTTP client
The description “A lightweight yet powerful HTTP client” can apply to various libraries in different programming languages. Here are some popular HTTP clients that fit this description:
Python
– `requests`: This is a very popular Python HTTP library that is user-friendly and powerful.
– `httpx`: Similar to `requests`, but supports asynchronous operations.
JavaScript
– `axios`: A Promise-based HTTP client for browsers and node.js.
– `fetch`: A built-in HTTP client API for browsers, which can also be used in node.js through polyfill.
Java
– `OkHttp`: An HTTP client for Java and Android.
– `Retrofit`: Based on OkHttp, it provides a type-safe HTTP client.
Go
– `net/http`: The HTTP client in Go’s standard library, simple and efficient.
– `gorequest`: An enhanced HTTP client that provides chainable calls.
Ruby
– `Faraday`: A flexible HTTP client library that supports multiple adapters.
– `HTTParty`: A simple HTTP client library that is easy to use.
PHP
– `Guzzle`: A powerful PHP HTTP client.
– `curl`: A PHP extension that provides a set of functions for handling URLs.
These clients typically have the following features:
– Lightweight: Small codebase, few dependencies, easy to integrate.
– Powerful: Supports HTTPS, HTTP/2, authentication, request retries, timeout settings, etc.
– Easy to use: Provides a clean API, making it simple to send HTTP requests.
The choice of client depends on your specific needs, including the programming language used, project requirements, and whether specific features (like asynchronous processing, file uploads, etc.) are needed.
WebSocket and Stomp
WebSocket and STOMP are two network protocols typically used for building real-time, bidirectional, and event-driven applications.
WebSocket
WebSocket is a network communication protocol that provides a way to perform full-duplex communication over a single TCP connection. This means that both the client and server can send messages at any time without polling. Here are some key features of WebSocket:
– Full-duplex communication: The client and server can send messages at any time without waiting for a request-response cycle.
– Long-lived connections: Once a WebSocket connection is established, it remains open until explicitly closed, reducing the overhead of repeated connections.
– Low latency: By reducing the number of HTTP handshakes, WebSocket can achieve faster message transmission.
– Event-driven: The server can proactively push messages to the client without the client needing to request them.
The WebSocket protocol is typically used in applications requiring real-time interaction, such as online gaming, live chat, and real-time trading systems.
STOMP (Simple Text Oriented Messaging Protocol)
STOMP is a simple text-oriented messaging protocol designed for message passing over WebSocket or other transport protocols. STOMP provides a framework-agnostic line format that allows clients and servers to communicate by sending simple text messages. Here are some key features of STOMP:
– Simplicity: The message format of STOMP is very simple, easy to understand and implement.
– Commands and frames: STOMP uses the concepts of commands and frames to define the structure and types of messages.
– Compatibility: STOMP can run over various transport protocols, including WebSocket, HTTP, and TCP.
– Support for message topics: Similar to message queues, STOMP allows clients to send messages to specific topics, which other clients can subscribe to receive messages.
STOMP is typically used to build message-driven applications where clients and servers need to interact through message passing, such as in microservices architectures.
The relationship between WebSocket and STOMP
WebSocket is a transport protocol, while STOMP is a messaging protocol. This means that STOMP can run on top of WebSocket, leveraging the persistent connection and low-latency features provided by WebSocket to achieve efficient message passing. By using these two protocols together, developers can build real-time and reliable messaging systems.
Introduction
OkHttps is a lightweight HTTP client framework developed based on OkHttp3. OkHttps provides a lightweight wrapper around OkHttp3 and adds some new features and functionalities to make network communication simpler and more efficient. Here are some key advantages of OkHttps:
1. Asynchronous preprocessor: OkHttps introduces an asynchronous preprocessor that allows network requests to be executed in the background thread, avoiding thread blocking and improving application responsiveness and performance.
2. Flexible upload and download progress monitoring and process control: It provides flexible upload and download progress monitoring and process control features, allowing developers to monitor the progress of network requests in real-time and handle responses during upload or download.
3. Chainable calls: OkHttps supports chainable calls, making the code cleaner and more readable. It also supports automatic wrapping and parsing of BaseURL, URL placeholders, HTTP, WebSocket, JSON, XML, etc., greatly reducing the repetitive labor for developers.
4. Synchronous interceptors, asynchronous preprocessors, callback executors, global listeners, callback blocking: These features help developers perform necessary processing before sending requests or after receiving responses, such as adding authentication information or modifying request parameters.
5. File upload and download (process control, progress monitoring): Supports file upload and download features and provides progress monitoring and process control capabilities.
6. Single method callbacks, fully utilizing Lambda expressions: Supports single method callbacks, allowing developers to use Lambda expressions to write callback functions, improving code readability and simplicity.
7. TCP connection pool, Http2: Supports TCP connection pools and Http2, which can further improve network communication performance and responsiveness.
The design of OkHttps seeks purity and elegance, allowing developers to write more efficient, concise, and stable code, thereby improving application performance and user experience.
// Build instanceHTTP http = HTTP.builder() .baseUrl("http://api.example.com") .addMsgConvertor(new GsonMsgConvertor()); .build();// Sync HTTPList<User> users = http.sync("/users") .get() // GET request .getBody() // Response body .toList(User.class); // Auto deserialize List // Async HTTPhttp.async("/users/1") .setOnResponse((HttpResult res) -> { // Auto deserialize Bean User user = res.getBody().toBean(User.class); }) .get(); // GET request// WebSockethttp.webSocket("/my-websocket") .setOnMessage((WebSocket ws, Message msg) -> { // Receive message from server Chat chat = msg.toBean(Chat.class); // Send message to server ws.send(chat); }) .listen(); // Start listening// Stomp protocolStomp.over(http.webSocket("wss://...").heatbeat(20, 20)) .topic("/my-topic", (Message msg) -> { // Received topic message String payload = msg.getPayload(); }) .connect(); // Connect to Stomp service
Open source address
Follow the public account and reply 20240804 to get it
We guess you might like:
[Open Source] Auxiliary College Education System, supports millions of user-level online education platform system
[Open Source] Integrated low-code development platform for smart manufacturing
[Open Source] Visual drag-and-drop programming, automatically generate projects, automatically generate code, import third-party components
[Open Source] Next-generation crawler platform that defines crawling processes graphically without writing code
[Open Source] DingTalk and Feishu style, includes front and back-end code, based on Flowable, an out-of-the-box low-code open-source professional workflow engine
Add WeChat to join relevant groups,
Note “Microservices” to join the group for discussion
Note “Low-code” to join the low-code group for discussion
Note “AI” to join the AI big data and data governance group for discussion
Note “Digital” to join the IoT and digital twin group for discussion
Note “Security” to join the security-related group for discussion
Note “Automation” to join the automation operation and maintenance group for discussion
Note “Trial” to apply for product trial
Note “Channel” to cooperate on channel information
Note “Customization” to customize projects, with full source code delivery