Skip to content

An interceptor for logging unirest-java requests as curl requests.

License

Notifications You must be signed in to change notification settings

sitture/unirest-curl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unirest-curl

An interceptor for logging Unirest requests as curl requests.

Build Github Publish Maven Publish Maven Central Maintainability License: MIT contributions welcome

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.

Setup

Add the following both unirest-java and unirest-curl dependencies:

Maven

<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>

Github Packages

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>

Gradle

compile 'com.github.sitture:unirest-curl:${version}'

Usage

To Intercept requests and log them as curl requests:

  1. 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);
    }
}
  1. 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. :)

Issues & Contributions

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.