How to Expose Your Spring Boot API with cpolar: A Complete Step‑by‑Step Guide

This tutorial walks you through setting up a local Java Spring Boot service, installing and configuring cpolar for HTTP tunneling, creating and fixing a public address, and using the cpolar listener to monitor and replay API requests, complete with code snippets and screenshots.

Java Architect Handbook
Java Architect Handbook
Java Architect Handbook
How to Expose Your Spring Boot API with cpolar: A Complete Step‑by‑Step Guide

Overview

This guide shows how to expose a local Java Spring Boot service to the public Internet for remote debugging using cpolar, a tunneling tool that works without a public IP.

1. Local environment

JDK 1.8

IntelliJ IDEA

Spring Boot

Maven

Tomcat 9.0

Postman

1.2 Build a Spring Boot service

Create a Spring Boot project and add a simple POST endpoint that echoes the request body.

@RestController
@RequestMapping("/test")
public class InterfaceTest {
    /**
     * Test interface
     * @param data request body
     * @return Map<String,String>
     */
    @PostMapping("/interTest")
    public Map<String,String> interTest(@RequestBody Map<String,String> data){
        System.out.println(data);
        if (data.size() > 0){
            return data;
        }
        data.put("code","404");
        return data;
    }
}

2. Internal network tunneling with cpolar

2.1 Install and configure cpolar

Windows : download the installer from the official site and follow the default steps.

Linux (domestic) :

curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash

Linux (overseas) : curl -sL https://git.io/cpolar | sudo bash Verify the installation: cpolar version Authenticate with the token obtained from the cpolar dashboard:

cpolar authtoken YOUR_TOKEN_HERE
cpolar token authentication
cpolar token authentication

2.2 Create a tunnel for the local Tomcat port 8080

In the cpolar web UI, create an HTTP tunnel with the following settings:

Tunnel name: any unique name

Protocol: HTTP

Local address: 8080

Domain type: free random domain

Region: China VIP

After creation, copy the generated public address.

cpolar tunnel creation
cpolar tunnel creation

2.3 Test the public address

Use Postman to send a POST request to {public_address}/test/interTest with a JSON body. Verify that the request reaches the Spring Boot service by checking the console output.

Postman request test
Postman request test

3. Reserve a stable public address

By default cpolar assigns a random domain that changes every 24 hours. To obtain a fixed address, reserve a sub‑domain (requires at least the Basic plan).

3.1 Reserve a sub‑domain

In the cpolar dashboard, go to Reserve , enter the desired sub‑domain name, and click Reserve . Copy the reserved sub‑domain.

Reserve sub‑domain
Reserve sub‑domain

3.2 Configure the tunnel to use the sub‑domain

Edit the previously created 8080 tunnel and set:

Domain type: Sub‑domain

Sub Domain: the reserved name (e.g., test01)

Save the changes. The public address now reflects the fixed sub‑domain.

Configure sub‑domain
Configure sub‑domain

3.3 Test the fixed public address

Send the same POST request to the new fixed URL using Postman and verify that the Spring Boot service receives it.

Fixed address test
Fixed address test

4. Use the cpolar listener

The listener (http://localhost:4040) shows request logs, response status, and allows replaying requests, which is useful for debugging.

4.1 Enable the listener

Edit the HTTP tunnel, open Advanced Settings , and enable the listening feature.

Enable listener
Enable listener

4.2 Monitor requests

Open a browser at http://localhost:4040. After sending a request to the service, the listener displays the request method, path, payload, and response status, facilitating rapid debugging.

Request monitoring
Request monitoring
backendJavaSpring Bootnetwork debuggingtunnelingAPI testingcpolar
Java Architect Handbook
Written by

Java Architect Handbook

Focused on Java interview questions and practical article sharing, covering algorithms, databases, Spring Boot, microservices, high concurrency, JVM, Docker containers, and ELK-related knowledge. Looking forward to progressing together with you.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.