Skip to content

fern-demo/plantstore-demo-java-sdk

Repository files navigation

Plantstore Java Library

fern shield

The Plantstore Java library provides convenient access to the Plantstore API from Java.

Usage

Instantiate and use the client with the following:

package com.example.usage;

import com.plantstore.api.PlantstoreApiClient;
import com.plantstore.api.resources.imdb.types.CreateMovieRequest;

public class Example {
    public static void main(String[] args) {
        PlantstoreApiClient client = PlantstoreApiClient
            .builder()
            .build();

        client.imdb().createMovie(
            CreateMovieRequest
                .builder()
                .title("title")
                .rating(1.1)
                .build()
        );
    }
}

Base Url

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

import com.plantstore.api.PlantstoreApiClient;

PlantstoreApiClient client = PlantstoreApiClient
    .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.plantstore.api.core.PlantstoreApiApiException;

try {
    client.imdb().createMovie(...);
} catch (PlantstoreApiApiException 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.plantstore.api.PlantstoreApiClient;
import okhttp3.OkHttpClient;

OkHttpClient customClient = ...;

PlantstoreApiClient client = PlantstoreApiClient
    .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 retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

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

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

Use the maxRetries request option to configure this behavior.

import com.plantstore.api.core.RequestOptions;

client.imdb().createMovie(
    ...,
    RequestOptions
        .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.plantstore.api.PlantstoreApiClient;
import com.plantstore.api.core.RequestOptions;

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

// Request level
client.imdb().createMovie(
    ...,
    RequestOptions
        .builder()
        .timeout(10)
        .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!

About

A Java SDK for the Plantstore-Demo API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages