SpaceTraders.Client 0.1.4

dotnet add package SpaceTraders.Client --version 0.1.4
                    
NuGet\Install-Package SpaceTraders.Client -Version 0.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpaceTraders.Client" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SpaceTraders.Client" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="SpaceTraders.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SpaceTraders.Client --version 0.1.4
                    
#r "nuget: SpaceTraders.Client, 0.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SpaceTraders.Client@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SpaceTraders.Client&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=SpaceTraders.Client&version=0.1.4
                    
Install as a Cake Tool

SpaceTraders.Client

Developer-friendly & type-safe Csharp SDK specifically catered to leverage SpaceTraders.Client API.

<div align="left"> <a href="https://www.speakeasy.com/?utm_source=space-traders-client&utm_campaign=csharp"><img src="https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454" /></a> <a href="https://opensource.org/licenses/MIT"> <img src="https://img.shields.io/badge/License-MIT-blue.svg" style="width: 100px; height: 28px;" /> </a> </div>

<br /><br />

This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.

Summary

SpaceTraders API: SpaceTraders is an open-universe game and learning platform that offers a set of HTTP endpoints to control a fleet of ships and explore a multiplayer universe.

The API is documented using OpenAPI. You can send your first request right here in your browser to check the status of the game server.

{
  "method": "GET",
  "url": "https://api.spacetraders.io/v2",
}

Unlike a traditional game, SpaceTraders does not have a first-party client or app to play the game. Instead, you can use the API to build your own client, write a script to automate your ships, or try an app built by the community.

We have a Discord channel where you can share your projects, ask questions, and get help from other players.

Table of Contents

SDK Installation

To add a reference to a local instance of the SDK in a .NET project:

dotnet add reference src/SpaceTraders/Client/SpaceTraders.Client.csproj

SDK Example Usage

Example

using SpaceTraders.Client;
using SpaceTraders.Client.Models.Requests;

var sdk = new SpaceTradersClient();

var res = await sdk.Status.GetAsync(security: new GetStatusSecurity() {
    AgentToken = "<YOUR_BEARER_TOKEN_HERE>",
});

// handle response

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
AgentToken http HTTP Bearer

To authenticate with the API the AgentToken parameter must be set when initializing the SDK client instance. For example:

using SpaceTraders.Client;
using SpaceTraders.Client.Models.Components;
using SpaceTraders.Client.Models.Requests;

var sdk = new SpaceTradersClient(agentToken: "<YOUR_BEARER_TOKEN_HERE>");

RegisterRequest req = new RegisterRequest() {
    Faction = FactionSymbol.Quantum,
    Symbol = "BADGER",
};

var res = await sdk.Agents.RegisterAsync(req);

// handle response

Per-Operation Security Schemes

Some operations in this SDK require the security scheme to be specified at the request level. For example:

using SpaceTraders.Client;
using SpaceTraders.Client.Models.Requests;

var sdk = new SpaceTradersClient();

var res = await sdk.Status.GetAsync(security: new GetStatusSecurity() {
    AgentToken = "<YOUR_BEARER_TOKEN_HERE>",
});

// handle response

Available Resources and Operations

<details open> <summary>Available methods</summary>

Agents

Contracts

Factions

  • All - List Factions
  • Get - Get Faction

Fleet

Status

  • Get - Get Status

Systems

</details>

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default, an API error will raise a SpaceTraders.Client.Models.Errors.APIException exception, which has the following properties:

Property Type Description
Message string The error message
Request HttpRequestMessage The HTTP request
Response HttpResponseMessage The HTTP response

When custom error responses are specified for an operation, the SDK may also throw their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the GetAsync method throws the following exceptions:

Error Type Status Code Content Type
SpaceTraders.Client.Models.Errors.APIException 4XX, 5XX */*

Example

using SpaceTraders.Client;
using SpaceTraders.Client.Models.Errors;
using SpaceTraders.Client.Models.Requests;

var sdk = new SpaceTradersClient();

try
{
    var res = await sdk.Status.GetAsync(security: new GetStatusSecurity() {
        AgentToken = "<YOUR_BEARER_TOKEN_HERE>",
    });

    // handle response
}
catch (Exception ex)
{
    if (ex is SpaceTraders.Client.Models.Errors.APIException)
    {
        // Handle default exception
        throw;
    }
}

Server Selection

Override Server URL Per-Client

The default server can be overridden globally by passing a URL to the serverUrl: string optional parameter when initializing the SDK client instance. For example:

using SpaceTraders.Client;
using SpaceTraders.Client.Models.Requests;

var sdk = new SpaceTradersClient(serverUrl: "https://api.spacetraders.io/v2");

var res = await sdk.Status.GetAsync(security: new GetStatusSecurity() {
    AgentToken = "<YOUR_BEARER_TOKEN_HERE>",
});

// handle response

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

SDK Created by Speakeasy

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.4 240 3/11/2025