Code Explainers

Code explainers tagged #http-client

java
public interface GitHubClient {
 
    @GetExchange("/users/{username}")
    GitHubUser getUser(@PathVariable String username);

Declarative HTTP clients in Spring

http-client declarative-api proxy
Intermediate 8 steps
rust
use axum::{
    extract::{Path, State},
    http::StatusCode,
    response::IntoResponse,

Building a GitHub proxy handler in Axum

shared-state http-client error-mapping
Intermediate 9 steps
java
package com.example.payments.config;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

Configuring a Stripe RestClient in Spring

dependency-injection http-client configuration
Intermediate 7 steps
java
public class GitHubUserClient {
 
    private final HttpClient http = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(10))

Calling the GitHub API with Java's HttpClient

http-client json-deserialization error-handling
Intermediate 9 steps
typescript
import { HttpService } from '@nestjs/axios';
import { Injectable, Logger, ServiceUnavailableException } from '@nestjs/common';
import { AxiosError } from 'axios';
import { catchError, firstValueFrom, retry, timer } from 'rxjs';

Resilient payment retries in NestJS

retry exponential-backoff rxjs
Advanced 8 steps
java
public OrderConfirmation submitOrder(Order order) throws IOException, InterruptedException {
    String payload = objectMapper.writeValueAsString(order);
 
    HttpRequest request = HttpRequest.newBuilder()

Posting an order with Java's HttpClient

http-client json-serialization error-handling
Intermediate 6 steps
java
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;

Streaming a file download with Java's HttpClient

http-client streaming file-io
Intermediate 6 steps
go
package payments
 
import (
	"context"

Fetching a charge over HTTP in Go

context-timeout http-client json-decoding
Intermediate 6 steps
python
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
 

Building a resilient requests Session

retries backoff http-client
Intermediate 7 steps
php
<?php
 
namespace App\Services;
 

Resilient HTTP retries with Laravel's client

http-client retry-logic error-handling
Intermediate 7 steps
java
@Service
public class PaymentGatewayClient {
 
    private static final Logger log = LoggerFactory.getLogger(PaymentGatewayClient.class);

Resilient payment calls with Spring Retry

retry backoff fault-tolerance
Intermediate 7 steps
java
@Service
public class GitHubClient {
 
    private final WebClient webClient;

Calling the GitHub API with Spring WebClient

reactive http-client dependency-injection
Intermediate 7 steps