Skip to content

HTTP Client

This page maps the namespaced SDK resource methods to HTTP routes. Most apps should import createSimulatorClient() and use the resource API directly.

ts
import { 
createSimulatorClient
} from '@my-swu/simulator-client'
const
simulatorClient
=
createSimulatorClient
({
// Base URL is the HTTP origin; resource methods append their route paths.
baseUrl
: 'http://127.0.0.1:4000',
})

Routes

SDK methodHTTP routeResponse
simulatorClient.system.health()GET /healthHealthResponse
simulatorClient.system.stats()GET /api/statsStatsResponse
simulatorClient.cards.get(ids)GET /api/cards?ids=...CardMetadata[]
simulatorClient.cards.resolveIds(references)POST /api/cards/resolveCardIdResolution[]
simulatorClient.cards.covered()GET /api/cards/coveredCoveredCard[]
simulatorClient.matches.create(request)POST /api/matchesMatchAccessResponse
simulatorClient.matches.join(match, request)POST /api/matches/{matchId}/joinMatchAccessResponse
simulatorClient.matches.get(match)GET /api/matches/{matchId}GameState
simulatorClient.matches.applyFormatEvent(access, command)POST /api/matches/{matchId}/format-eventsGameState
simulatorClient.limitedEvents.create(request)POST /api/limited-eventsLimitedEventAccessResponse
simulatorClient.limitedEvents.join(event, request?)POST /api/limited-events/{eventId}/joinLimitedEventAccessResponse
simulatorClient.limitedEvents.get(event)GET /api/limited-events/{eventId}LimitedEventSnapshot
simulatorClient.limitedEvents.applyCommand(access, command)POST /api/limited-events/{eventId}/commandsLimitedEventSnapshot

Request validation

The SDK validates every request body before sending it:

ts
// The SDK validates this request body before network I/O.
const 
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} await
simulatorClient
.
matches
.
create
({
hostDeck
:
premierHostDeck
,
})

Malformed bodies throw SdkValidationError before network I/O.

Response validation

Successful responses are validated against generated JSON schemas before they resolve. Schema drift or malformed response JSON throws SdkValidationError.

HTTP errors

Non-2xx responses throw EngineHttpError:

ts
import { 
EngineHttpError
} from '@my-swu/simulator-client'
try { // Missing resources reject with EngineHttpError instead of returning null. await
simulatorClient
.
matches
.
get
('missing-match')
} catch (
error
) {
if (
error
instanceof
EngineHttpError
) {
// Log stable fields that help route UI handling and diagnostics.
console
.
warn
(
error
.
status
,
error
.
code
,
error
.
method
,
error
.
url
)
} }

When the server returns a valid engine error payload, code and message come from that payload. If the body is empty, not JSON, or not shaped like api-error-response, the error still includes status, method, url, and the raw responseText when present.

Released under the MIT License.