Eternaltwin
Eternaltwin API client for Haxe.
Supports all Haxe server targets: JavaScript (Node.js), Neko, HashLink, C++, Python.
Installation
Install using haxelib:
haxelib install eternaltwin
Then add the dependency in your .hxml build file:
-lib eternaltwin
-lib tink_core
Getting started
import eternaltwin.client.Auth;
import eternaltwin.client.HttpEtwinClient;
import eternaltwin.user.UserId;
import tink.core.Outcome;
class Main {
static function main() {
var client = new HttpEtwinClient("https://eternaltwin.org");
var userId = new UserId("9f310484-963b-446b-af69-797feec6813f");
client.getUser(Auth.guest(), userId).handle(function(outcome) {
switch (outcome) {
case Success(user): trace(user);
case Failure(error): trace("Error: " + error.message);
}
});
}
}
Using an access token
var auth = Auth.fromToken("my-oauth-access-token");
client.getSelf(auth).handle(function(outcome) {
switch (outcome) {
case Success(ctx):
switch (ctx) {
case UserAuth(u): trace("Logged in as: " + u.user.displayName);
default: trace(ctx);
}
case Failure(error): trace("Error: " + error.message);
}
});
API
EtwinClient interface
| Method | Signature | Description |
|---|---|---|
getSelf | (auth: Auth) -> Promise<AuthContext> | Get the auth context for the current session |
getUser | (auth: Auth, userId: UserId) -> Promise<User> | Get a user by ID |
Auth helper
| Method | Description |
|---|---|
Auth.guest() | Unauthenticated (no Authorization header) |
Auth.fromToken(key) | Bearer token authentication |
Multi-target compilation
haxe build.hxml # JS (primary)
haxe build.hxml -neko build/etwin.n # Neko
haxe build.hxml -hl build/etwin.hl # HashLink
haxe build.hxml -cpp build/cpp # C++
Tasks
haxe test.hxml: Run the test suitehaxe build.hxml: Build the library (JS target)
License
AGPL-3.0-or-later