Skip to main content

server

Attribute Macro server 

Source
#[server]
Expand description

Blessed preset: HTTP server with OpenAPI and serve.

Combines #[http] + #[serve(http)] into a single attribute.

§Example

use server_less::server;

#[derive(Clone)]
struct MyApi;

#[server]
impl MyApi {
    pub fn list_items(&self) -> Vec<String> { vec![] }
    pub fn create_item(&self, name: String) -> String { name }
}

// Equivalent to:
// #[http]
// #[serve(http)]
// impl MyApi { ... }

§Options

  • prefix - URL prefix (e.g., #[server(prefix = "/api")])
  • openapi - Toggle OpenAPI generation (default: true)
  • health - Custom health check path (default: /health)
  • config - Config struct type for config subcommand wiring (e.g., #[server(config = MyConfig)])
  • config_cmd - Config subcommand name override or false to disable (default: "config")
  • name - App name (forwarded from #[app]; default: kebab-case struct name)
  • description - App description for CLI help and OpenAPI info
  • version - Version string; false disables --version (default: CARGO_PKG_VERSION)
  • homepage - URL used in OpenAPI and OpenRPC info fields