### Run with defaults Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-webapi.md Shows how to build and start the Nexus API with default configuration. The example disables key republishing for private setups and blocks until Ctrl-C. ```rust use nexus_webapi::api_context::ApiContextBuilder; use nexus_webapi::NexusApiBuilder; #[tokio::main] async fn main() -> Result<(), Box> { let ctx = ApiContextBuilder::from_default_config_dir().try_build().await?; // Blocks until Ctrl-C, then gracefully shuts down. NexusApiBuilder::new(ctx) .enable_key_republisher(false) // skip DHT publishing for private setups .start(None) .await?; Ok(()) } ``` -------------------------------- ### Basic StackManager setup example Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-common.md Shows basic usage of StackManager::setup with a default StackConfig. After a successful call, RedisConnector and Neo4jConnector are initialized globally. ```rust use nexus_common::{StackConfig, StackManager}; #[tokio::main] async fn main() -> Result<(), Box> { StackManager::setup(&StackConfig::default()).await?; // RedisConnector and Neo4jConnector are now initialized globally. Ok(()) } ``` -------------------------------- ### Start Nexus API server from config path Source: https://github.com/pubky/pubky-nexus/blob/main/nexus-webapi/README.md Rust example that starts the Nexus API server by loading configuration from a specified folder path using NexusApi::start_from_path. ```rust use nexus_watcher::builder::NexusWatcher; use std::path::PathBuf; #[tokio::main] async fn main() -> Result<(), Box> { NexusApi::start_from_path(PathBuf::from("path/to/config/folder")).await?; Ok(()) } ``` -------------------------------- ### Minimal NexusWatcher example Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-watcher.md Minimal example of creating and starting a NexusWatcher with debug logging. The start method blocks until Ctrl-C is received. ```rust use nexus_watcher::{service::NexusWatcher, NexusWatcherBuilder}; #[tokio::main] async fn main() -> Result<(), Box> { NexusWatcherBuilder(Default::default()) .log_level(nexus_common::Level::Debug) .start(None) // blocks until Ctrl-C .await?; Ok(()) } ``` -------------------------------- ### Loading DaemonConfig Example Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-common-config.md Example usage of read_or_create_config_file to load the daemon configuration within a tokio runtime. ```rust use nexus_common::DaemonConfig; #[tokio::main] async fn main() -> Result<(), Box> { let config = DaemonConfig::read_or_create_config_file( std::path::PathBuf::from("~/.pubky-nexus"), ).await?; println!("api on {}; watcher HS {}", config.api.public_addr, config.watcher.homeserver); Ok(()) } ``` -------------------------------- ### Start from config file with custom shutdown Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-webapi.md Shows how to start the Nexus API from a config directory with a custom shutdown signal. The example creates a watch channel and sends a shutdown signal after 60 seconds. ```rust use nexus_common::utils::create_shutdown_rx; use nexus_webapi::NexusApi; let (tx, rx) = tokio::sync::watch::channel(false); tokio::spawn(async move { tokio::time::sleep(std::time::Duration::from_secs(60)).await; let _ = tx.send(true); }); NexusApi::start_from_path("config/dir".into(), Some(rx)).await?; ``` -------------------------------- ### Start Nexus API server with builder Source: https://github.com/pubky/pubky-nexus/blob/main/nexus-webapi/README.md Rust example that builds and runs the Nexus API server using the NexusApi builder. Requires tokio runtime. ```rust use nexus_webapi::builder::NexusApi; #[tokio::main] async fn main() -> Result<(), Box> { // Build and run the Nexus API server NexusApi::builder().run().await?; Ok(()) } ``` -------------------------------- ### Start Nexus Watcher from config path Source: https://github.com/pubky/pubky-nexus/blob/main/nexus-watcher/README.md Starts the Nexus Watcher by loading configuration from a specified folder path. Uses start_from_path with a PathBuf argument and explicitly returns Ok(()) after awaiting the service. ```rust use nexus_watcher::service::NexusWatcher; use std::path::PathBuf; #[tokio::main] async fn main() -> Result<(), Box> { NexusWatcher::start_from_path(PathBuf::from("path/to/config/folder")).await?; Ok(()) } ``` -------------------------------- ### DaemonLauncher struct and start method Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexusd.md Defines the DaemonLauncher struct and its async start method. The start method takes a config directory and an optional shutdown receiver, returning a Result with DynError. The startup sequence reads/creates DaemonConfig, validates scheduled jobs, builds the API context, and runs the API, watcher, and job runner concurrently. ```rust #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DaemonLauncher {} impl DaemonLauncher { pub async fn start(config_dir: PathBuf, shutdown_rx: Option>) -> Result<(), DynError> } ``` -------------------------------- ### Set up Docker environment with docker compose Source: https://github.com/pubky/pubky-nexus/blob/main/README.md Sets up the Docker environment for Nexus. Copy the environment template and start the lean stack (Neo4j, Redis, Redis Insight) or include Postgres for watcher tests using the 'tests' profile. To always start Postgres without passing '--profile tests', uncomment 'COMPOSE_PROFILES=tests' in '.env'. ```bash cd docker cp .env-sample .env # Lean stack: Neo4j + Redis + Redis Insight docker compose up -d # With Postgres (for watcher tests) docker compose --profile tests up -d ``` -------------------------------- ### StackManager setup method signature Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-common.md Defines the StackManager type and its setup method signature. The setup method is async and returns a Result, indicating it can fail if a different StackConfig was already initialized. ```rust pub struct StackManager; impl StackManager { pub async fn setup(config: &StackConfig) -> Result<(), DynError> } ``` -------------------------------- ### Start Nexus Watcher with builder Source: https://github.com/pubky/pubky-nexus/blob/main/nexus-watcher/README.md Starts the Nexus Watcher using the builder API. Requires the tokio runtime and the nexus_watcher crate. The run() method returns a Result that is propagated as the main function's return value. ```rust use nexus_watcher::service::NexusWatcher; #[tokio::main] async fn main() -> Result<(), Box> { NexusWatcher::builder().run().await } ``` -------------------------------- ### Start the local observability stack with Docker Compose Source: https://github.com/pubky/pubky-nexus/blob/main/README.md Starts the bundled local observability stack, which combines the OpenTelemetry Collector with Grafana, Tempo, Prometheus, and Loki. Runs independently of the database services. ```bash docker compose -f docker/docker-compose.observability.yml up -d ``` -------------------------------- ### Example — serve with on-demand derivation Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-webapi-models.md Illustrates the flow for serving a static file variant with lazy derivation, showing the call chain and behavior under load. ```rust // A user requests /static/files///small for an image. // static_files_handler -> serve_file_variant -> VariantController.run_variant: // identify (image metadata), then convert to the small variant under one permit; // a 503 is returned while the pool is saturated (QueuedGate waits instead). ``` -------------------------------- ### PostId validation example Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-webapi-models.md Shows how to construct a valid PostId from a string and that invalid input is rejected. ```rust use nexus_webapi::models::PostId; let id: PostId = "00000039YD9DP".to_string().try_into()?; // Ok assert!(PostId::try_from("not-crockford!".to_string()).is_err()); // invalid length/charset ``` -------------------------------- ### Dual-write example Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexusd.md Shows how to invoke a dual-write from your data layer, mirroring writes to the new source. Requires the migration type to implement the Migration trait. ```rust use nexusd::migrations::MigrationManager; // In the application's data layer, mirror writes to the new source: MigrationManager::dual_write::(Box::new(record)).await?; ``` -------------------------------- ### GET /v0/search/users/by_name/{prefix} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Searches for users by name prefix. Returns a list of user IDs. ```APIDOC ## GET /v0/search/users/by_name/{prefix} ### Description Searches for users by name prefix. Returns a list of user IDs. ### Method GET ### Endpoint /v0/search/users/by_name/{prefix} ### Parameters #### Path Parameters - **prefix** (UsernamePrefix) - Required - The username prefix to search for #### Query Parameters - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip - **limit** (BoundedLimit<50,200>) - Optional - Maximum number of results to return (default: 50) ### Response #### Success Response (200) - **UserSearch** (array of user IDs) - List of matching user IDs #### Response Example ```json [ "user_id_1", "user_id_2" ] ``` ### Errors - 400 Bad Request - 429 Too Many Requests - 500 Internal Server Error ``` -------------------------------- ### ApiContextBuilder::from_default_config_dir Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-webapi.md Creates an ApiContextBuilder with the default config directory (~/.pubky-nexus). This is the starting point for building an ApiContext. ```APIDOC ## ApiContextBuilder::from_default_config_dir ### Description Creates an ApiContextBuilder with the default config directory `~/.pubky-nexus`. This is the starting point for building an ApiContext. ### Method from_default_config_dir ### Signature `pub fn from_default_config_dir() -> Self` ### Parameters None ### Returns - **Self** - A new ApiContextBuilder instance. ### Example rust use nexus_webapi::api_context::ApiContextBuilder; let builder = ApiContextBuilder::from_default_config_dir(); ``` -------------------------------- ### GET /v0/search/tags/by_prefix/{prefix} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Searches for tags by prefix. Returns a list of tag labels. ```APIDOC ## GET /v0/search/tags/by_prefix/{prefix} ### Description Searches for tags by prefix. Returns a list of tag labels. ### Method GET ### Endpoint /v0/search/tags/by_prefix/{prefix} ### Parameters #### Path Parameters - **prefix** (string) - Required - The tag prefix to search for #### Query Parameters - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip - **limit** (BoundedLimit<20,100>) - Optional - Maximum number of results to return ### Response #### Success Response (200) - **TagSearch** (array of strings) - List of tag labels #### Response Example ```json [ "tag1", "tag2" ] ``` ### Errors - 400 Bad Request - 429 Too Many Requests - 500 Internal Server Error ``` -------------------------------- ### Load DaemonConfig with ConfigLoader Source: https://github.com/pubky/pubky-nexus/blob/main/nexus-common/README.md Loads a DaemonConfig from a configuration file using the ConfigLoader trait. The example expands the home directory path '~/.pubky-nexus' and prints the loaded configuration. ```rust use nexus_common::config::{ConfigLoader, DaemonConfig}; use std::path::Path; use nexus_common::types::DynError; #[tokio::main] async fn main() -> Result<(), DynError> { let cfg: DaemonConfig = DaemonConfig::read_config_file( config::expand_home_dir("~/.pubky-nexus".into()) ).await?; println!("Loaded config: {:#?}", cfg); Ok(()) } ``` -------------------------------- ### GET /v0/stream/resources Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a stream of resources based on the specified filters. ```APIDOC ## GET /v0/stream/resources ### Description Retrieves a stream of resources based on the specified filters. ### Method GET ### Endpoint /v0/stream/resources ### Parameters #### Query Parameters - **app** (string) - Optional - App filter. - **tags** (Tags) - Optional - Comma-separated tags (max 5, OR). - **sorting** (ResourceSorting) - Optional - Sorting method (default timeline). - **order** (SortOrder) - Optional - Sort order (default descending). - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<10,100>) - Optional - Maximum number of results (default 10). - **start** (f64) - Optional - Start timestamp. - **end** (f64) - Optional - End timestamp. - **viewer_id** (PubkyId) - Optional - The ID of the requesting user. ### Response #### Success Response (200) - **Vec** - List of resource views. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### GET /v0/bootstrap/{user_id} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Fetches the initial boot payload for a given user, including user streams, post streams, file details, bootstrap IDs, indexing status, and notifications. ```APIDOC ## GET /v0/bootstrap/{user_id} ### Description Fetches the initial boot payload for a given user, including user streams, post streams, file details, bootstrap IDs, indexing status, and notifications. ### Method GET ### Endpoint /v0/bootstrap/{user_id} ### Parameters #### Path Parameters - **user_id** (PubkyId) - Required - The user's Pubky ID ### Response #### Success Response (200) - **users** (UserStream) - User stream data - **posts** (PostStream) - Post stream data - **files** (Array) - List of file details - **ids** (BootstrapIds) - Bootstrap IDs - **indexed** (boolean) - Whether the user is indexed - **notifications** (Array) - List of notifications #### Response Example { "users": {}, "posts": {}, "files": [], "ids": {}, "indexed": true, "notifications": [] } ### Errors - **429** - Rate limit exceeded - **500** - Internal server error ``` -------------------------------- ### Cache-first bulk read example Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-common-db.md Shows how to use FileDetails::get_by_ids to perform a cache-first bulk read. The keys are a vector of slices, and the result is a vector of Option. ```rust use nexus_common::models::{file::FileDetails, traits::Collection}; let keys: Vec<&[&str]> = vec![&["owner_pk", "file00000000001"]]; let files: Vec> = FileDetails::get_by_ids(&keys).await?; ``` -------------------------------- ### GET /v0/stream/users/username Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Searches for users by username prefix. ```APIDOC ## GET /v0/stream/users/username ### Description Searches for users by username prefix. ### Method GET ### Endpoint /v0/stream/users/username ### Parameters #### Query Parameters - **username** (UsernamePrefix) - Required - The username prefix to search for. - **viewer_id** (PubkyId) - Optional - The ID of the requesting user. - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<20,20>) - Optional - Maximum number of results (default 20). ### Response #### Success Response (200) - **UserStream** - List of UserView objects. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### Building an ApiContext with a custom ApiConfig Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-webapi.md Example of constructing an ApiContext using the default config directory and a custom ApiConfig, then calling try_build(). Requires the `?` operator, so it must be used in a function returning a Result. ```rust use nexus_webapi::api_context::ApiContextBuilder; use nexus_common::ApiConfig; let api_config = ApiConfig::default(); // or load from TOML let ctx = ApiContextBuilder::from_default_config_dir() .api_config(api_config) .try_build() .await?; ``` -------------------------------- ### GET /v0/search/users/by_id/{prefix} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Searches for users by user ID prefix. Returns a list of user IDs. ```APIDOC ## GET /v0/search/users/by_id/{prefix} ### Description Searches for users by user ID prefix. Returns a list of user IDs. ### Method GET ### Endpoint /v0/search/users/by_id/{prefix} ### Parameters #### Path Parameters - **prefix** (UserIdPrefix) - Required - The user ID prefix to search for (minimum length: USER_ID_SEARCH_MIN_PREFIX_LEN) #### Query Parameters - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip - **limit** (BoundedLimit<50,200>) - Optional - Maximum number of results to return (default: 50) ### Response #### Success Response (200) - **UserSearch** (array of user IDs) - List of matching user IDs #### Response Example ```json [ "user_id_1", "user_id_2" ] ``` ### Errors - 400 Bad Request - 429 Too Many Requests - 500 Internal Server Error ``` -------------------------------- ### GET /v0/stream/posts Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a stream of posts based on the specified source and filters. ```APIDOC ## GET /v0/stream/posts ### Description Retrieves a stream of posts based on the specified source and filters. ### Method GET ### Endpoint /v0/stream/posts ### Parameters #### Query Parameters - **source** (StreamSourceKind) - Optional - Source of the stream (default all). - **viewer_id** (PubkyId) - Optional - The ID of the requesting user. - **observer_id** (PubkyId) - Optional - Observer ID for certain sources. - **author_id** (PubkyId) - Optional - Author ID for certain sources. - **post_id** (PostId) - Optional - Post ID for certain sources. - **sorting** (StreamSorting) - Optional - Sorting method. - **order** (SortOrder) - Optional - Sort order. - **tags** (Tags) - Optional - Comma-separated tags (max 5, OR). - **depth** (u8) - Optional - Depth of the stream. - **domain_tags** (Tags) - Optional - Domain tags (required for wot_domain). - **kind** (PubkyAppPostKind) - Optional - Post kind filter. - **exclude_kinds** (PostKinds) - Optional - Post kinds to exclude. - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<10,50>) - Optional - Maximum number of results (default 10). - **start** (f64) - Optional - Start timestamp. - **end** (f64) - Optional - End timestamp. - **include_attachment_metadata** (bool) - Optional - Whether to include attachment metadata. ### Response #### Success Response (200) - **PostStreamDetailed** - Detailed post stream. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### NexusWatcher public API Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-watcher.md Public API of NexusWatcher from nexus-watcher/src/service/mod.rs. start_from_path loads watcher-config.toml from config_dir, falling back to start_from_daemon when absent; start_from_daemon loads config.toml and converts via WatcherConfig::from(DaemonConfig); start persists the primary homeserver and runs four periodic tasks. ```rust pub struct NexusWatcher {} impl NexusWatcher { pub fn builder() -> NexusWatcherBuilder; pub async fn start_from_path(config_dir: PathBuf, shutdown_rx: Option>) -> Result<(), DynError>; pub async fn start_from_daemon(config_dir: PathBuf, shutdown_rx: Option>) -> Result<(), DynError>; pub async fn start(shutdown_rx: Receiver, config: WatcherConfig) -> Result<(), DynError>; } ``` -------------------------------- ### GET /v0/info Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves server information including description, homepage, license, name, repository, version, commit hash, last index snapshot, and base file URL. ```APIDOC ## GET /v0/info ### Description Retrieves server information including description, homepage, license, name, repository, version, commit hash, last index snapshot, and base file URL. ### Method GET ### Endpoint /v0/info ### Response #### Success Response (200) - **description** (string) - Server description - **homepage** (string) - Server homepage URL - **license** (string) - Server license - **name** (string) - Server name - **repository** (string) - Server repository URL - **version** (string) - Server version - **commit_hash** (string) - Git commit hash - **last_index_snapshot** (string) - Last index snapshot - **base_file_url** (string) - Base file URL #### Response Example { "description": "string", "homepage": "string", "license": "string", "name": "string", "repository": "string", "version": "string", "commit_hash": "string", "last_index_snapshot": "string", "base_file_url": "string" } ### Errors - **429** - Rate limit exceeded - **500** - Internal server error ``` -------------------------------- ### GET /v0/stream/users Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a stream of users based on the specified source and filters. ```APIDOC ## GET /v0/stream/users ### Description Retrieves a stream of users based on the specified source and filters. ### Method GET ### Endpoint /v0/stream/users ### Parameters #### Query Parameters - **source** (UserStreamSource) - Optional - Source of the stream (default followers). - **user_id** (PubkyId) - Optional - User ID for certain sources. - **viewer_id** (PubkyId) - Optional - The ID of the requesting user. - **author_id** (PubkyId) - Optional - Author ID for certain sources. - **post_id** (PostId) - Optional - Post ID for certain sources. - **reach** (StreamReach) - Optional - Reach filter. - **timeframe** (Timeframe) - Optional - Timeframe filter (default all_time). - **preview** (bool) - Optional - Whether to return a preview. - **depth** (u8) - Optional - Depth of the stream. - **tags** (Tags) - Optional - Comma-separated tags (only for starter_pack). - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<5,20>) - Optional - Maximum number of results (default 5). ### Response #### Success Response (200) - **UserStream** - List of UserView objects. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### GET /v0/stream/resources/ids Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a stream of resource IDs based on the specified filters. ```APIDOC ## GET /v0/stream/resources/ids ### Description Retrieves a stream of resource IDs based on the specified filters. ### Method GET ### Endpoint /v0/stream/resources/ids ### Parameters #### Query Parameters - **app** (string) - Optional - App filter. - **tags** (Tags) - Optional - Comma-separated tags (max 5, OR). - **sorting** (ResourceSorting) - Optional - Sorting method (default timeline). - **order** (SortOrder) - Optional - Sort order (default descending). - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<10,100>) - Optional - Maximum number of results (default 10). - **start** (f64) - Optional - Start timestamp. - **end** (f64) - Optional - End timestamp. ### Response #### Success Response (200) - **ResourceKeyStream** - Object containing resource_ids and last_score. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### GET /v0/search/posts/by_content Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Searches for posts by content query. Supports filtering by author and kind, and pagination. ```APIDOC ## GET /v0/search/posts/by_content ### Description Searches for posts by content query. Supports filtering by author and kind, and pagination. ### Method GET ### Endpoint /v0/search/posts/by_content ### Parameters #### Query Parameters - **q** (PostSearchQuery) - Required - Search query (2-30 characters, up to 4 terms) - **author** (PubkyId) - Optional - Filter by author user ID - **kind** (PubkyAppPostKind) - Optional - Filter by post kind - **skip** (BoundedSkip<1000>) - Optional - Number of results to skip - **limit** (BoundedLimit<20,100>) - Optional - Maximum number of results to return (default: 20) ### Response #### Success Response (200) - **PostsByContentSearch** (array) - List of posts ordered by relevance #### Response Example ```json [ { "post_id": "string", "content": "string" } ] ``` ### Errors - 400 Bad Request - 429 Too Many Requests - 500 Internal Server Error ### Bucket **expensive** ``` -------------------------------- ### GET /v0/search/users/by_tags Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Searches for users by tags. Returns a list of users ordered by tagger count. ```APIDOC ## GET /v0/search/users/by_tags ### Description Searches for users by tags. Returns a list of users ordered by tagger count. ### Method GET ### Endpoint /v0/search/users/by_tags ### Parameters #### Query Parameters - **tags** (Tags) - Required - Comma-separated list of 1-5 tags - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip - **limit** (BoundedLimit<20,200>) - Optional - Maximum number of results to return (default: 20) ### Response #### Success Response (200) - **UsersByTagSearch** (array) - List of users with tagger counts #### Response Example ```json [ { "user_id": "string", "tagger_count": 0 } ] ``` ### Errors - 400 Bad Request - 429 Too Many Requests - 500 Internal Server Error ### Bucket **expensive** ``` -------------------------------- ### GET /v0/post/{author_id}/{post_id}/bookmark Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves the bookmark information for a specific post, if it exists for the given viewer. ```APIDOC ## GET /v0/post/{author_id}/{post_id}/bookmark ### Description Retrieves the bookmark information for a specific post, if it exists for the given viewer. ### Method GET ### Endpoint /v0/post/{author_id}/{post_id}/bookmark ### Parameters #### Path Parameters - **author_id** (PubkyId) - Required - The ID of the post author. - **post_id** (PostId) - Required - The ID of the post. #### Query Parameters - **viewer_id** (PubkyId) - Required - The ID of the requesting user. ### Response #### Success Response (200) - **Bookmark** - Object containing id and indexed_at. #### Error Response - **404** - Post not found or no bookmark exists. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### Run Nexus service with cargo run Source: https://github.com/pubky/pubky-nexus/blob/main/README.md Runs the Nexus service with Cargo. The default config file is '$HOME/.pubky-nexus/config.toml'. Use '--config-dir' to specify a custom config folder. Services can be run individually, such as 'watcher' and 'api', and a database clear command is available before starting the watcher. ```bash # Run with defaults values. The config file will default from $HOME/.pubky-nexus/config.toml cargo run -p nexusd # Run from config file cargo run -p nexusd -- --config-dir="custom/config/folder" # There is also an option to run services individually # Useful to run a database clear command before start running the watcher # cargo run -p nexusd -- db clear --yes cargo run -p nexusd -- watcher cargo run -p nexusd -- api ``` -------------------------------- ### Configure a per-minute scheduled job in config.toml Source: https://github.com/pubky/pubky-nexus/blob/main/README.md Another example of a scheduled job configuration. The cron expression runs every minute at second 0, demonstrating the seconds-first format. ```toml [jobs.reindex] cron = "0 * * * * *" # every minute at second 0 ``` -------------------------------- ### GET /v0/search/posts/by_tag/{tag} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Searches for posts by tag. Supports sorting, filtering by user and reach, and pagination. ```APIDOC ## GET /v0/search/posts/by_tag/{tag} ### Description Searches for posts by tag. Supports sorting, filtering by user and reach, and pagination. ### Method GET ### Endpoint /v0/search/posts/by_tag/{tag} ### Parameters #### Path Parameters - **tag** (TagLabel) - Required - The tag label to search for #### Query Parameters - **sorting** (StreamSorting) - Optional - Sorting order - **user_id** (PubkyId) - Optional - Filter by user ID - **reach** (StreamReach) - Optional - Filter by reach (requires user_id) - **start** (timestamp) - Optional - Start time for filtering - **end** (timestamp) - Optional - End time for filtering - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip - **limit** (BoundedLimit<20,200>) - Optional - Maximum number of results to return (default: 20) ### Response #### Success Response (200) - **PostsByTagSearch** (array) - List of posts matching the tag #### Response Example ```json [ { "post_id": "string", "title": "string" } ] ``` ### Errors - 400 Bad Request - 429 Too Many Requests - 500 Internal Server Error ``` -------------------------------- ### GET /v0/stream/users/ids Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a stream of user IDs based on the same query contract as the user stream. ```APIDOC ## GET /v0/stream/users/ids ### Description Retrieves a stream of user IDs based on the same query contract as the user stream. ### Method GET ### Endpoint /v0/stream/users/ids ### Parameters #### Query Parameters - **source** (UserStreamSource) - Optional - Source of the stream (default followers). - **user_id** (PubkyId) - Optional - User ID for certain sources. - **viewer_id** (PubkyId) - Optional - The ID of the requesting user. - **author_id** (PubkyId) - Optional - Author ID for certain sources. - **post_id** (PostId) - Optional - Post ID for certain sources. - **reach** (StreamReach) - Optional - Reach filter. - **timeframe** (Timeframe) - Optional - Timeframe filter (default all_time). - **preview** (bool) - Optional - Whether to return a preview. - **depth** (u8) - Optional - Depth of the stream. - **tags** (Tags) - Optional - Comma-separated tags (only for starter_pack). - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<5,20>) - Optional - Maximum number of results (default 5). ### Response #### Success Response (200) - **UserIdStream** - Array of Pubky ID strings. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### Parse ApiConfig from TOML with ConfigLoader Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-common.md Shows how to parse an `ApiConfig` from a TOML string using `ConfigLoader::try_from_str`. The example config includes a Redis URL and Neo4j connection details. ```rust use nexus_common::{config::file::ConfigLoader, ApiConfig}; let cfg = ApiConfig::try_from_str( r#" [stack.db] redis = "redis://localhost:6379" [stack.db.neo4j] uri = "bolt://localhost:7687" password = "12345678" "#, )?; ``` -------------------------------- ### GET /v0/resource/by-uri Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Resolves a resource URI to its resource ID and returns the resource tags. The URI is normalized before resolution. ```APIDOC ## GET /v0/resource/by-uri ### Description Resolves a resource URI to its resource ID and returns the resource tags. The URI is normalized before resolution. ### Method GET ### Endpoint /v0/resource/by-uri ### Parameters #### Query Parameters - **uri** (string) - Required - Resource URI. - **viewer_id** (string) - Optional - Viewer identifier. - **skip_tags** (integer) - Optional - Number of tags to skip. - **limit_tags** (integer) - Optional - Maximum number of tags to return. - **limit_taggers** (integer) - Optional - Maximum number of taggers to return. ### Response #### Success Response (200) - **resource** (object) - Resource details. - **tags** (array of TagDetails) - List of tag details. #### Error Responses - **400** - Invalid URI. - **404** - Resource not found. - **429** - Too many requests. - **500** - Internal server error. ``` -------------------------------- ### GET /static/files/{owner_id}/{file_id} (legacy) Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Serves the main variant of a file without the variant segment. Returns 404 if the file is missing. ```APIDOC ## GET /static/files/{owner_id}/{file_id} (legacy) ### Description Serves the main variant of a file without the variant segment. Returns 404 if the file is missing. ### Method GET ### Endpoint /static/files/{owner_id}/{file_id} ### Parameters #### Path Parameters - **owner_id** (string) - Required - PubkyId of the file owner. - **file_id** (string) - Required - File identifier. ### Response #### Success Response (200) - **body** (binary) - Raw file bytes (main variant). #### Error Responses - **404** - File not found. - **429** - Too many requests. - **500** - Internal server error. ``` -------------------------------- ### GET /v0/user/{user_id}/following Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a paginated list of Pubky IDs of users that the specified user follows. ```APIDOC ## GET /v0/user/{user_id}/following ### Description Retrieves a paginated list of Pubky IDs of users that the specified user follows. ### Method GET ### Endpoint /v0/user/{user_id}/following ### Parameters #### Path Parameters - **user_id** (string) - Required - The Pubky ID of the user. #### Query Parameters - **skip** (integer) - Optional - Number of users to skip (max 10000). - **limit** (integer) - Optional - Number of users to return (50-200, default 50). ### Response #### Success Response (200) - **following** (array) - List of Pubky IDs. #### Response Example { "following": [] } #### Error Responses - **400** - Bad request. - **404** - User not found. - **429** - Too many requests. - **500** - Internal server error. ``` -------------------------------- ### GET /static/avatar/{user_id} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Serves the user's image file if it is an indexed image. Uses a fail-fast media gate that returns 503 when the media pool is saturated. ```APIDOC ## GET /static/avatar/{user_id} ### Description Serves the user's image file if it is an indexed image. Uses a fail-fast media gate that returns 503 when the media pool is saturated. ### Method GET ### Endpoint /static/avatar/{user_id} ### Parameters #### Path Parameters - **user_id** (string) - Required - User identifier. ### Response #### Success Response (200) - **body** (binary) - Image file bytes. #### Error Responses - **404** - User or image not found. - **429** - Too many requests. - **500** - Internal server error. - **503** - Media pool saturated. ``` -------------------------------- ### GET /v0/stream/posts/keys Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a stream of post keys (author_id:post_id) based on the same query contract as the post stream. ```APIDOC ## GET /v0/stream/posts/keys ### Description Retrieves a stream of post keys (author_id:post_id) based on the same query contract as the post stream. ### Method GET ### Endpoint /v0/stream/posts/keys ### Parameters #### Query Parameters - **source** (StreamSourceKind) - Optional - Source of the stream (default all). - **viewer_id** (PubkyId) - Optional - The ID of the requesting user. - **observer_id** (PubkyId) - Optional - Observer ID for certain sources. - **author_id** (PubkyId) - Optional - Author ID for certain sources. - **post_id** (PostId) - Optional - Post ID for certain sources. - **sorting** (StreamSorting) - Optional - Sorting method. - **order** (SortOrder) - Optional - Sort order. - **tags** (Tags) - Optional - Comma-separated tags (max 5, OR). - **depth** (u8) - Optional - Depth of the stream. - **domain_tags** (Tags) - Optional - Domain tags (required for wot_domain). - **kind** (PubkyAppPostKind) - Optional - Post kind filter. - **exclude_kinds** (PostKinds) - Optional - Post kinds to exclude. - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<10,50>) - Optional - Maximum number of results (default 10). - **start** (f64) - Optional - Start timestamp. - **end** (f64) - Optional - End timestamp. - **include_attachment_metadata** (bool) - Optional - Whether to include attachment metadata. ### Response #### Success Response (200) - **PostKeyStream** - Object containing post_keys and last_post_score. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### GET /v0/user/{user_id}/followers Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves a paginated list of Pubky IDs of users who follow the specified user. ```APIDOC ## GET /v0/user/{user_id}/followers ### Description Retrieves a paginated list of Pubky IDs of users who follow the specified user. ### Method GET ### Endpoint /v0/user/{user_id}/followers ### Parameters #### Path Parameters - **user_id** (string) - Required - The Pubky ID of the user. #### Query Parameters - **skip** (integer) - Optional - Number of followers to skip (max 10000). - **limit** (integer) - Optional - Number of followers to return (50-200, default 50). ### Response #### Success Response (200) - **followers** (array) - List of Pubky IDs. #### Response Example { "followers": [] } #### Error Responses - **400** - Bad request. - **404** - User not found. - **429** - Too many requests. - **500** - Internal server error. ``` -------------------------------- ### GET /v0/post/{author_id}/{post_id}/taggers/{label} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves users who tagged a post with a specific label, with pagination. ```APIDOC ## GET /v0/post/{author_id}/{post_id}/taggers/{label} ### Description Retrieves users who tagged a post with a specific label, with pagination. ### Method GET ### Endpoint /v0/post/{author_id}/{post_id}/taggers/{label} ### Parameters #### Path Parameters - **author_id** (PubkyId) - Required - The ID of the post author. - **post_id** (PostId) - Required - The ID of the post. - **label** (string) - Required - The tag label. #### Query Parameters - **viewer_id** (PubkyId) - Optional - The ID of the requesting user. - **depth** (integer) - Optional - Ignored. - **skip** (BoundedSkip<10_000>) - Optional - Number of results to skip. - **limit** (BoundedLimit<40,100>) - Optional - Maximum number of results to return (default 40). ### Response #### Success Response (200) - **TaggersInfoResponse** - Object containing tagger information. #### Error Response - **400** - Bad request. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### StackManager mismatched config error handling Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-common.md Demonstrates error handling when calling StackManager::setup with a different StackConfig after the first successful call. The second setup is expected to fail with an error message indicating the stack was already initialized with a different configuration. ```rust use nexus_common::{Level, StackConfig, StackManager}; #[tokio::main] async fn main() { let a = StackConfig::default(); let mut b = StackConfig::default(); b.log_level = Level::Debug; StackManager::setup(&a).await.expect("first setup ok"); match StackManager::setup(&b).await { Err(e) => eprintln!("second setup rejected: {e}"), // "already initialized with a different StackConfig" Ok(_) => unreachable!(), } } ``` -------------------------------- ### Example: Retrieve top influencers for the current week Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/api-reference/nexus-common-models-core.md Shows how to call Influencers::get_influencers with a timeframe of ThisWeek and no user_id or reach, then iterate over the returned top influencers printing each user_id and score. The result is unwrapped with unwrap_or_default() to handle None. ```rust use nexus_common::models::user::Influencers; use nexus_common::types::Timeframe; let top = Influencers::get_influencers(None, None, 0, 20, Timeframe::ThisWeek, false).await?; for (user_id, score) in top.unwrap_or_default().iter() { println!("{user_id}: {score}"); } ``` -------------------------------- ### GET /v0/post/{author_id}/{post_id}/details Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Retrieves detailed metadata for a specific post, including content, author, and attachments. ```APIDOC ## GET /v0/post/{author_id}/{post_id}/details ### Description Retrieves detailed metadata for a specific post, including content, author, and attachments. ### Method GET ### Endpoint /v0/post/{author_id}/{post_id}/details ### Parameters #### Path Parameters - **author_id** (PubkyId) - Required - The ID of the post author. - **post_id** (PostId) - Required - The ID of the post. ### Response #### Success Response (200) - **PostDetails** - Object containing content, id, indexed_at, author, kind, uri, attachments, and lock. #### Error Response - **404** - Post not found. - **429** - Rate limit exceeded. - **500** - Internal server error. ``` -------------------------------- ### GET /v0/user/{user_id}/relationship/{viewer_id} Source: https://github.com/pubky/pubky-nexus/blob/main/_autodocs/endpoints.md Returns the relationship between the target user and the specified viewer, indicating whether the target follows the viewer and vice versa. ```APIDOC ## GET /v0/user/{user_id}/relationship/{viewer_id} ### Description Returns the relationship between the target user and the specified viewer. ### Method GET ### Endpoint /v0/user/{user_id}/relationship/{viewer_id} ### Parameters #### Path Parameters - **user_id** (string) - Required - The Pubky ID of the target user. - **viewer_id** (string) - Required - The Pubky ID of the viewer. ### Response #### Success Response (200) - **following** (boolean) - Whether the target user follows the viewer. - **followed_by** (boolean) - Whether the target user is followed by the viewer. #### Response Example { "following": true, "followed_by": false } #### Error Responses - **404** - User not found. - **429** - Too many requests. - **500** - Internal server error. ```