Echo API

A maven library of a /echo API that echoes HTTP request’s details back to the caller.

Gerald Nguyen
2 min readNov 30, 2022

The need for this library arose when I wanted assurance that my HTTP client was sending correctly formulated HTTP messages.

Another use of this /echo API is to capture and debug the remote calls from another service. Imagine you are providing a webhook endpoint. Before you even build one, you first need to know what incoming messages look like. Supplying an /echo API endpoint in the webhook’s registration allows you to capture and log all incoming messages

Screenshot of a Postman request

Demo

You can open https://echook.azurewebsites.net/echo on your browser, Postman, or call it from an API to see the /echo in action

Note: This site is hosted on Azure free tier. If it is a while since its last execution, it may take some time to respond. Otherwise, you can clone the https://github.com/geraldnguyen/echo-server project and run the application locally

Integration

pom.xml

<dependency>
<groupId>io.github.geraldnguyen</groupId>
<artifactId>echo</artifactId>
<version>1.0.0</version>
</dependency>

EchoServerApplication.java

import nguyen.gerald.echo.EnableEchoController;

@SpringBootApplication
@EnableEchoController
public class EchoServerApplication {
public static void main(String[] args) {
SpringApplication.run(EchoServerApplication.class, args);
}
}

Features

The following information is echoed back in JSON format:

  • Path
  • Protocol
  • Headers
  • Query string
  • URL-encoded form submission
  • Multi-part form submission

Limitation

The parsing of the query string and URL-encoded body depends on a deprecated class HttpUtils that supports only default encoding. The extraction code also does not handle malformed strings well.

Hash fragment (#abc)

Browser does not include hash fragment in the HTTP request message. Java servlet specification does not provide any way to extract the original URL either.

Hence there is no way to extract and echo hash fragment back.

The library’s source code is available on my GitHub. Feel free to explore and try it out.

If you like this article, please follow me for more quality content. Thank you.

--

--

Gerald Nguyen
Gerald Nguyen

Written by Gerald Nguyen

Engineering Lead. I write about software development, and sometimes writing itself. Mostly original. https://bit.ly/geraldnguyen

No responses yet