An interceptor for logging Unirest requests as curl requests.
All notable changes to this project are documented in CHANGELOG.md. The format is based on Keep a Changelog and adheres to Semantic Versioning.
The latest version of the library can be found under Releases.
Add the following both unirest-java
and unirest-curl
dependencies:
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java-core</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.github.sitture</groupId>
<artifactId>unirest-curl</artifactId>
<version>${version}</version>
</dependency>
If you would like to use github package instead of maven central, add the following repository to pom.xml.
<repositories>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/sitture/unirest-curl</url>
</repository>
</repositories>
compile 'com.github.sitture:unirest-curl:${version}'
To Intercept requests and log them as curl requests:
- Create a Logger object using the RequestLogger interface. E.g. To log requests to stdout.
public class CurlLogger implements RequestLogger {
@Override
public void log(final String curlRequest) {
System.out.println(curlRequest);
}
}
- Add the interceptor to Unirest config:
Unirest.config().interceptor(new CurlInterceptor(new CurlLogger()));
// Example request
Unirest.get("https://reqres.in/api/users?page=2").asJson();
That's it. Now every time a request is made from Unirest, it'll log the request as curl. :)
Please open an issue here on GitHub if you have a problem, suggestion, or other comment.
Pull requests are welcome and encouraged! Any contributions should include new or updated unit tests as necessary to maintain thorough test coverage.
Read CONTRIBUTING.md for guidelines.