Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Vers Java API Library

This library provides convenient access to the Vers REST API from Java.

It is generated with Sterling.

Installation

Maven

<dependency>
    <groupId>sh.vers</groupId>
    <artifactId>vers-sdk</artifactId>
    <version>1.20.0</version>
</dependency>

Gradle

implementation 'sh.vers:vers-sdk:1.20.0'

Usage

import sh.vers.sdk.VersClient;

public class Example {
    public static void main(String[] args) throws Exception {
        VersClient client = new VersClient(
            "https://api.vers.sh",  // or set VERS_BASE_URL env var
            "your-api-key"   // or set VERS_API_KEY env var
        );

        // List all VMs
        var response = client.listVms(null, null);
        System.out.println(response.body());

        // Create a new root VM
        var vm = client.createNewRootVm(java.util.Map.of("vm_config", java.util.Map.of()), null);
        System.out.println(vm.body());

        client.close();
    }
}

Configuration

import sh.vers.sdk.VersClient;
import java.time.Duration;

VersClient client = new VersClient(
    "https://api.vers.sh",       // base URL
    "your-api-key",       // API key
    2,                    // max retries
    Duration.ofSeconds(30), // timeout
    null                  // optional custom HttpClient
);

Error handling

import sh.vers.sdk.Errors.*;

try {
    client.deleteVm("nonexistent-id", null);
} catch (NotFoundError e) {
    System.out.println("Not found: " + e.getStatus() + " " + e.getMessage());
} catch (APIError e) {
    System.out.println("API error: " + e.getStatus());
}

Retries

Requests are automatically retried up to 2 times on 5xx errors and connection failures, with exponential backoff and jitter. The client respects Retry-After headers (capped at 60s).

Per-request options

import sh.vers.sdk.RequestOptions;
import java.time.Duration;

RequestOptions options = new RequestOptions()
    .addHeader("X-Custom-Header", "value")
    .setTimeout(Duration.ofSeconds(60));

client.listVms(null, options);

Requirements

  • Java 11+
  • Jackson Databind

License

MIT

About

Vers SDK — generated from the Vers OpenAPI spec

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages