Client and REST API

Client

DearDiary.connectFunction
connect(base_url; username, password, token)::Client

Build a Client pointed at base_url.

Pass username and password to sign in via POST /auth and store the issued token. Pass token instead to attach an already-issued bearer token. Pass neither when the server runs with auth disabled; the client will work without an Authorization header.

Arguments

  • base_url::AbstractString: Base URL of the server (with or without trailing slash).
  • username::Optional{AbstractString}: Username for sign-in.
  • password::Optional{AbstractString}: Password for sign-in.
  • token::Optional{AbstractString}: Pre-issued bearer token.

Returns

A Client ready to issue authenticated requests.

source
DearDiary.disconnectFunction
disconnect(client::Client)::Nothing

Clear the local token. The server is stateless so this is purely a client-side reset; any copies of the token issued earlier remain valid until they expire.

source
DearDiary.refresh_token!Function
refresh_token!(client::Client)::Client

Call POST /auth/refresh and replace the client's token with the freshly-minted one.

source
DearDiary.whoamiFunction
whoami(client::Client)::UserResponse

Resolve the user behind the current token via GET /auth/me. Also refreshes the cached client.user.

source

REST API

DearDiary.APIConfigType
APIConfig

A struct to hold the configuration for the API server.

Fields

  • host::String: The host of the API server.
  • port::UInt16: The port of the API server.
  • db_file::String: The path to the DuckDB database file.
  • jwt_secret::String: The JWT secret for authentication.
  • enable_auth::Bool: Whether to enable authentication or not.
  • cors_origins::Vector{String}: Browser origins allowed to call the API. Use ["*"] to allow any origin (default in development).
  • artifact_backend::String: Which AbstractArtifactStore backend handles Resource bytes. One of "inline" (default, bytes stored inline in the DB), "filesystem", or "s3". Selected at server startup by the DEARDIARY_ARTIFACT_BACKEND env var.
  • artifact_fs_root::String: Root directory for the FilesystemStore backend. Honoured only when artifact_backend == "filesystem". Created on first write.
  • artifact_s3_bucket::String: Bucket name for the S3Store backend.
  • artifact_s3_endpoint::String: Scheme + host for S3 requests (e.g. https://s3.us-east-1.amazonaws.com, http://localhost:9000 for MinIO).
  • artifact_s3_region::String: Region used in the SigV4 credential scope.
  • artifact_s3_access_key::String, artifact_s3_secret_key::String: SigV4 credentials.
  • enable_ui::Bool: Set true to make DearDiary.run boot the embedded Bonito dashboard on ui_host:ui_port alongside the REST API server. Defaults to true.
  • ui_host::String: Host the dashboard binds to. Defaults to 127.0.0.1.
  • ui_port::UInt16: Port the dashboard binds to. Defaults to 9001.
source
DearDiary.runFunction
run(; env_file::String=".env")

Start the server. Reads configuration from env_file (defaults to .env). The server binds to 127.0.0.1:9000 unless overridden by DEARDIARY_HOST and DEARDIARY_PORT.

source