Dev

Four tools for testing backend integrations locally

Capture local email with Mailpit, inspect sandbox webhooks, and exercise HTTP failures and REST client mapping without depending on production services.

Four tools for testing backend integrations locally

Testing an external integration locally is easier when I can see what crosses the network. I use Mailpit for outgoing email, Webhook.site for a first look at sandbox callbacks, and public HTTP fixtures to explore client behavior.

These examples use Spring Boot 3.3, Kotlin, Java 21, and Docker Compose.

Match the tool to the integration boundary

An email template, a payment callback, and a slow upstream response all require different evidence. I want to inspect the rendered email, capture the callback headers and body, or reproduce a failure that the upstream sandbox rarely emits. It helps to choose tools that reveal the relevant part of the exchange.

ToolUseWhere it runsLimitation
MailpitInspect outbound SMTP and message renderingLocal Docker containerSelect the local mail profile before sending
Webhook.siteInspect incoming third-party callbacksHosted receiverKeep production data and credentials out
httpbin.orgRequest delays, statuses, and header echoesPublic HTTP endpointAvailability and timing vary
JSONPlaceholderExplore REST resources and DTO mappingPublic HTTP endpointThe fake write responses don’t persist data

I use public endpoints for interactive investigation. Tests that run in CI need fixtures I control so a remote outage doesn’t become a failed build.

Capture outgoing mail with Mailpit

A local verification email should stay on the development machine. Mailpit provides an SMTP endpoint on port 1025 and a web UI on port 8025. It captures messages for inspection without relaying them by default. The UI lets me check the HTML and plain-text renderings and see whether an attachment arrived.

1
2
3
4
5
6
7
8
9
10
11
# docker-compose.yml
services:
  mailpit:
    image: axllent/mailpit:latest
    container_name: mailpit
    restart: unless-stopped
    ports:
      - "1025:1025" # SMTP port
      - "8025:8025" # Web UI port
    environment:
      MP_MAX_MESSAGES: 500

Point the local Spring Boot profile, application-local.yml, at the capture service. Mailpit’s default local SMTP configuration does not require authentication or TLS.

1
2
3
4
5
6
7
8
9
10
11
# src/main/resources/application-local.yml
spring:
  mail:
    host: localhost
    port: 1025
    properties:
      mail:
        smtp:
          auth: false
          starttls:
            enable: false

After starting Compose and activating the local profile, send the message through JavaMailSender and open http://localhost:8025. I check the recipient and subject first, then the actual link in both MIME versions. If the Spring process also runs in Compose, use the Mailpit service name for the mail host. Inside its own container, localhost refers to the Spring container.

Keep the test SMTP settings in the local profile. A production SMTP account in the default configuration can send development messages to real recipients by accident.

Record a sandbox callback with Webhook.site

Payment providers and OAuth integrations can be difficult to debug from docs alone. A sandbox callback captured by Webhook.site shows the incoming HTTP method, query parameters, headers, and raw body. For example, a provider may deliver a signature in X-Hub-Signature-256, or encode a nested value differently from the documentation sample.

I use the service’s Copy as cURL action to capture the request, point the copied sandbox request at localhost:8080, and replay it when working on the controller and DTO mapping. Keep the original body encoding when the verification logic depends on raw bytes. A tunnel such as ngrok or Cloudflare Tunnel is useful later if the provider must call the development server directly.

Anyone with a free receiver URL may be able to view incoming requests. Send sandbox data and sample secrets only. Keep production API keys, real payment records, and customer information out of hosted captures.

Reproduce delays and server errors with httpbin

The normal success response doesn’t exercise a timeout or a 503 branch. httpbin makes those responses easy to ask for directly.

1
2
# Inspect a 503 response
curl -i -sS https://httpbin.org/status/503
1
2
3
4
HTTP/2 503
access-control-allow-origin: *
content-length: 0
content-type: text/html; charset=utf-8

A second request introduces a two-second delay. The time shown by curl includes network overhead and can vary.

1
2
# Inspect a two-second delay (about 2.6 seconds with network overhead in this example)
curl -sS -w "\nHTTP_CODE:%{http_code} TIME:%{time_total}s\n" https://httpbin.org/delay/2
1
2
3
4
5
6
7
8
9
10
11
12
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.7.1"
  },
  "method": "GET",
  "origin": "203.0.113.10",
  "url": "https://httpbin.org/delay/2"
}
HTTP_CODE:200 TIME:2.595131s

To see whether a request header made it to the server, send it to the echo endpoint.

1
2
# Ask the server to echo a custom header
curl -sS -H "X-Trace-Id: req-20240916" https://httpbin.org/headers
1
2
3
4
5
6
7
8
{
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.7.1",
    "X-Trace-Id": "req-20240916"
  }
}

Spring’s JdkClientHttpRequestFactory can give a RestClient a one-second read timeout. With that setup, /delay/2 exercises ResourceAccessException and /status/503 exercises HttpServerErrorException.ServiceUnavailable. Keeping them separate makes the handling policy easier to verify. A read timeout and a completed HTTP response with an error status provide different evidence about what happened upstream.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// src/main/kotlin/com/example/demo/client/HttpBinClientConfig.kt
package com.example.demo.client

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.JdkClientHttpRequestFactory
import org.springframework.web.client.RestClient
import java.net.http.HttpClient
import java.time.Duration

@Configuration
class HttpBinClientConfig {

    @Bean
    fun httpBinRestClient(builder: RestClient.Builder): RestClient {
        val httpClient = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(1))
            .build()

        val requestFactory = JdkClientHttpRequestFactory(httpClient).apply {
            setReadTimeout(Duration.ofSeconds(1))
        }

        return builder
            .baseUrl("https://httpbin.org")
            .requestFactory(requestFactory)
            .build()
    }
}

Use the public endpoint for an interactive check. A self-hosted httpbin container, WireMock, or MockWebServer gives repeatable timing and response fixtures for automated tests.

Prototype REST mapping with JSONPlaceholder

JSONPlaceholder provides sample /posts and /users resources. I can check that the client maps the shape of a conventional REST response while a partner API is still unavailable.

1
2
# Fetch one post
curl -sS https://jsonplaceholder.typicode.com/posts/1
1
2
3
4
5
6
{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

The write endpoints are useful for exercising request serialization and mapping the returned body.

1
2
3
4
# Send a create request (simulated response)
curl -sS -X POST https://jsonplaceholder.typicode.com/posts \
  -H "Content-Type: application/json" \
  -d '{"title":"test","body":"hello","userId":1}'
1
2
3
4
5
6
{
  "title": "test",
  "body": "hello",
  "userId": 1,
  "id": 101
}

That id: 101 is a simulated response. A subsequent GET /posts/101 returns 404 because the API didn’t persist the POST. Use a stateful local mock or a test database when the test needs to prove create-then-read behavior.

Choose repeatable checks for CI

  • Check a rendered message in Mailpit before testing mail delivery with a sandbox account.
  • Replay a sanitized callback locally when verifying payload mapping or header handling.
  • Exercise the timeout and HTTP error paths separately with a server you control.
  • Use JSONPlaceholder to explore response shapes and local stateful fixtures for write semantics.
  • Keep CI independent of shared public services by using WireMock, MockWebServer, or Testcontainers.

JSONPlaceholder guide

This post is licensed under CC BY 4.0 by the author.