Skip to content

mavenagi/mavenagi-java

Repository files navigation

Mavenagi Java Library

fern shield Maven Central

The Mavenagi Java library provides convenient access to the Mavenagi APIs from Java.

Table of Contents

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

package com.example.usage;

import com.mavenagi.MavenAGI;
import com.mavenagi.resources.actions.types.ActionsSearchRequest;

public class Example {
    public static void main(String[] args) {
        MavenAGI client = MavenAGI
            .builder()
            .credentials("<username>", "<password>")
            .build();

        client.actions().search(
            ActionsSearchRequest
                .builder()
                .build()
        );
    }
}

Environments

This SDK allows you to configure different environments for API requests.

import com.mavenagi.MavenAGI;
import com.mavenagi.core.Environment;

MavenAGI client = MavenAGI
    .builder()
    .environment(Environment.Production)
    .build();

Base Url

You can set a custom base URL when constructing the client.

import com.mavenagi.MavenAGI;

MavenAGI client = MavenAGI
    .builder()
    .url("https://example.com")
    .build();

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.

import com.mavenagi.core.MavenagiApiApiException;

try {
    client.actions().search(...);
} catch (MavenagiApiApiException e) {
    // Do something with the API exception...
}

Advanced

Custom Client

This SDK is built to work with any instance of OkHttpClient. By default, if no client is provided, the SDK will construct one. However, you can pass your own client like so:

import com.mavenagi.MavenAGI;
import okhttp3.OkHttpClient;

OkHttpClient customClient = ...;

MavenAGI client = MavenAGI
    .builder()
    .httpClient(customClient)
    .build();

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the maxRetries client option to configure this behavior.

import com.mavenagi.MavenAGI;

MavenAGI client = MavenAGI
    .builder()
    .maxRetries(1)
    .build();

Timeouts

The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.

import com.mavenagi.MavenAGI;
import com.mavenagi.core.RequestOptions;

// Client level
MavenAGI client = MavenAGI
    .builder()
    .timeout(10)
    .build();

// Request level
client.actions().search(
    ...,
    RequestOptions
        .builder()
        .timeout(10)
        .build()
);

Custom Headers

The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level.

import com.mavenagi.MavenAGI;
import com.mavenagi.core.RequestOptions;

// Client level
MavenAGI client = MavenAGI
    .builder()
    .addHeader("X-Custom-Header", "custom-value")
    .addHeader("X-Request-Id", "abc-123")
    .build();
;

// Request level
client.actions().search(
    ...,
    RequestOptions
        .builder()
        .addHeader("X-Request-Header", "request-value")
        .build()
);

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Installation

Gradle

Add the dependency in your build.gradle file:

dependencies {
  implementation 'com.mavenagi:mavenagi-java'
}

Maven

Add the dependency in your pom.xml file:

<dependency>
  <groupId>com.mavenagi</groupId>
  <artifactId>mavenagi-java</artifactId>
  <version>1.2.27</version>
</dependency>

About

Maven AGI Java SDK

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages