Class Client
- Direct Known Subclasses:
ClientAuth
Provides access to the Lichess API.
This interface provides access to the public API of Lichess (which doesn't
need a Lichess account.)
The ClientAuth
interface provides access to the authenticated
API of Lichess (which needs a Lichess account.)
Example of how to get a reference to a Client
interface
Client client = Client.basic();
// Tada!
// And then use it...
var user = client.users().byId("lichess");
For accessing authenticated parts of the API, one needs a token with
appropriate access rights / scopes. This library support PKCE Authorization
Code flow (auth(Consumer, Consumer)
), but one can also create a
Personal Access Token manually.
Example of how to get a reference to a ClientAuth
interface
String token = ... // Token with scope email:read
ClientAuth client = Client.auth(token);
// Tada!
// And then use it...
var email = client.account().emailAddress();
The responses from the API are modelled with One
<T>
and Many
<T>
"containers".
Their documentation covers different ways of accessing the contents of the containers.
The contents of the containers are typically data models from the chariot.model
package.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
static final record
static interface
static final record
static interface
static enum
OAuth scopes representing different permissions -
Field Summary
Fields inherited from class chariot.internal.ClientBase
analysisHandler, botHandler, broadcastsHandler, challengesHandler, client, customHandler, externalEngineHandler, fideApiHandler, gamesHandler, openingExplorerHandler, puzzlesHandler, simulsHandler, studiesHandler, tablebaseHandler, teamsHandler, tokenHandler, tournamentsHandler, usersHandler
-
Method Summary
Modifier and TypeMethodDescriptionanalysis()
Access Lichess cloud evaluations database.asAuth()
Retrieves anOpt
containing aClientAuth
if this is such a client, otherwise empty.static ClientAuth
Creates a default client using the provided token to use the authenticated parts of the APIstatic ClientAuth
auth
(Consumer<Builders.ConfigBuilder> params, String token) Creates a customizable client using the provided configuration parameters builder.static Client.AuthResult
auth
(Consumer<Builders.ConfigBuilder> config, Consumer<URI> uriHandler, Consumer<Client.PkceConfig> pkce) Use OAuth PKCE flow to make it possible for your user to grant access to your application.static ClientAuth
auth
(Consumer<Builders.ConfigBuilder> params, Supplier<char[]> token) Creates a customizable client using the provided configuration parameters builder.static Client.AuthResult
auth
(Consumer<URI> uriHandler, Consumer<Client.PkceConfig> pkce) Use OAuth PKCE flow to make it possible for your user to grant access to your application.static ClientAuth
Creates a default client using the provided token to use the authenticated parts of the APIstatic Client
basic()
Creates a default clientstatic Client
basic
(Consumer<Builders.ConfigBuilder> params) Creates a customized clientbot()
Access Lichess online bots.
For more bot operations, seeClientAuth.bot()
Relay chess events on Lichess.Open-ended challenges.custom()
Use chariot for custom endpointsExternal engine.fide()
Download FIDE player infogames()
Access games and TV channels, played on Lichess.static Client
load
(Preferences prefs) Creates a customized client from a preferences node
Seestore(Preferences)
static ClientAuth
load
(Preferences prefs, String token) Creates an authenticated customized client from a preferences node with provided tokenvoid
logging
(Consumer<Builders.LoggingBuilder> params) Configure logging levelsLookup positions from the Lichess opening explorer.puzzles()
Access Lichess puzzle history and dashboard.simuls()
Access simuls played on Lichess.boolean
store
(Preferences prefs) Stores the client configuration into the provided preferences nodestudies()
Access Lichess studies.Lookup positions from the Lichess tablebase server.teams()
Access and manage Lichess teams and their members.Access Arena and Swiss tournaments played on Lichess.users()
Access registered users on Lichess.withPkce
(Consumer<URI> uriHandler, Consumer<Client.PkceConfig> pkce) Use OAuth PKCE flow to make it possible for your user to grant access to your application.Use a pre-created Personal Access Token to use the authenticated API
String token = ... Client basic = Client.basic(); ClientAuth auth = basic.withToken(token); var challengeResult = auth.challenges().challenge(...);
Use a pre-created Personal Access Token to use the authenticated API
Supplier<char[]> token = ... Client basic = Client.basic(); ClientAuth auth = basic.withToken(token); var challengeResult = auth.challenges().challenge(...);
Methods inherited from class chariot.internal.ClientBase
config, personalAccessTokenForm, requestHandler, scopes, scopes, testTokens, testTokens, token
-
Method Details
-
users
Access registered users on Lichess. -
analysis
Access Lichess cloud evaluations database.- Overrides:
analysis
in classchariot.internal.ClientBase
-
bot
Access Lichess online bots.
For more bot operations, seeClientAuth.bot()
- Overrides:
bot
in classchariot.internal.ClientBase
-
broadcasts
Relay chess events on Lichess.Official broadcasts are maintained by Lichess, but you can create your own broadcasts to cover any live game or chess event. You will need to publish PGN on a public URL so that Lichess can pull updates from it. Alternatively, you can push PGN updates to Lichess using this API.
Broadcasts are organized in tournaments, which have several rounds, which have several games. You must first create a tournament, then you can add rounds to them.
- Overrides:
broadcasts
in classchariot.internal.ClientBase
-
challenges
Open-ended challenges. For authenticated challenges, seeChallengesApiAuth
- Overrides:
challenges
in classchariot.internal.ClientBase
-
externalEngine
External engine. For engine management, seeExternalEngineApiAuth
- Overrides:
externalEngine
in classchariot.internal.ClientBase
-
fide
Download FIDE player info- Overrides:
fide
in classchariot.internal.ClientBase
-
games
Access games and TV channels, played on Lichess.- Overrides:
games
in classchariot.internal.ClientBase
-
openingExplorer
Lookup positions from the Lichess opening explorer.- Overrides:
openingExplorer
in classchariot.internal.ClientBase
-
puzzles
Access Lichess puzzle history and dashboard.- Overrides:
puzzles
in classchariot.internal.ClientBase
-
simuls
Access simuls played on Lichess.- Overrides:
simuls
in classchariot.internal.ClientBase
-
studies
Access Lichess studies.- Overrides:
studies
in classchariot.internal.ClientBase
-
tablebase
Lookup positions from the Lichess tablebase server.- Overrides:
tablebase
in classchariot.internal.ClientBase
-
teams
Access and manage Lichess teams and their members.- Overrides:
teams
in classchariot.internal.ClientBase
-
tournaments
Access Arena and Swiss tournaments played on Lichess.- Overrides:
tournaments
in classchariot.internal.ClientBase
-
custom
Use chariot for custom endpoints- Overrides:
custom
in classchariot.internal.ClientBase
-
store
Stores the client configuration into the provided preferences node- Overrides:
store
in classchariot.internal.ClientBase
- Parameters:
prefs
- The preferences node to store this client configuration to
-
basic
Creates a default client -
auth
Creates a default client using the provided token to use the authenticated parts of the API- Parameters:
token
- A token to use for the authenticated parts of the API
-
basic
Creates a customized client- Parameters:
params
- A configuration parameters builder
-
withToken
Use a pre-created Personal Access Token to use the authenticated API
String token = ... Client basic = Client.basic(); ClientAuth auth = basic.withToken(token); var challengeResult = auth.challenges().challenge(...);
- Parameters:
token
- pre-created Personal Access Token - @see Personal Access Token
-
withToken
Use a pre-created Personal Access Token to use the authenticated API
Supplier<char[]> token = ... Client basic = Client.basic(); ClientAuth auth = basic.withToken(token); var challengeResult = auth.challenges().challenge(...);
- Parameters:
token
- pre-created Personal Access Token - @see Personal Access Token
-
auth
Creates a customizable client using the provided configuration parameters builder.- Parameters:
params
- A configuration parameters builder
-
auth
Creates a customizable client using the provided configuration parameters builder.- Parameters:
params
- A configuration parameters builder
-
auth
Creates a default client using the provided token to use the authenticated parts of the API- Parameters:
token
- A token to use for the authenticated parts of the API
-
withPkce
Use OAuth PKCE flow to make it possible for your user to grant access to your application.
Client basic = Chariot.basic(); AuthResult authResult = basic.withPkce( uri -> System.out.format("Visit %s to review and grant access%n", uri), pkce -> pkce.scope(Scope.challenge_read, Scope.challenge_write)); if (! (authResult instanceof AuthOk ok)) return; ClientAuth auth = ok.client(); var challengeResult = auth.challenges().challenge(...);
- Parameters:
uriHandler
- The generated Lichess URI that your user can visit to review and approve granting access to your applicationpkce
- Configuration of for instance which scopes if any that the resulting Access Token should include.
-
auth
Use OAuth PKCE flow to make it possible for your user to grant access to your application.
AuthResult authResult = Client.auth( uri -> System.out.format("Visit %s to review and grant access%n", uri), pkce -> pkce.scope(Scope.challenge_read, Scope.challenge_write)); if (! (authResult instanceof AuthOk ok)) return; ClientAuth auth = ok.client(); var challengeResult = auth.challenges().challenge(...);
- Parameters:
uriHandler
- The generated Lichess URI that your user can visit to review and approve granting access to your applicationpkce
- Configuration of for instance which scopes if any that the resulting Access Token should include.
-
auth
public static Client.AuthResult auth(Consumer<Builders.ConfigBuilder> config, Consumer<URI> uriHandler, Consumer<Client.PkceConfig> pkce) Use OAuth PKCE flow to make it possible for your user to grant access to your application.
AuthResult authResult = Client.auth( conf -> conf.api("http://localhost:9663"), uri -> System.out.format("Visit %s to review and grant access%n", uri), pkce -> pkce.scope(Scope.challenge_read, Scope.challenge_write)); if (! (authResult instanceof AuthOk ok)) return; ClientAuth auth = ok.client(); var challengeResult = auth.challenges().challenge(...);
- Parameters:
config
- Customized client configuration such as enabling logging and number of retries etc.uriHandler
- The generated Lichess URI that your user can visit to review and approve granting access to your applicationpkce
- Configuration of for instance which scopes if any that the resulting Access Token should include.
-
load
Creates a customized client from a preferences node
Seestore(Preferences)
- Parameters:
prefs
-A configuration preferences node
if (client instanceof ClientAuth auth) ...
-
load
Creates an authenticated customized client from a preferences node with provided token- Parameters:
prefs
- A configuration preferences nodetoken
- A token to use for the authenticated parts of the API
-
asAuth
Retrieves anOpt
containing aClientAuth
if this is such a client, otherwise empty. -
logging
Configure logging levels
-