Attributes

Every attribute, what it's for, and where to learn more. Import each one from margaret::framework::macros.

The container and the command line

AttributeWhat it's for
#[singleton]a shared object in the container
#[constructor]how a singleton is built
#[console_command]a console command
#[process]what a command, route, middleware, service, or task does

HTTP

AttributeWhat it's for
#[responds_to_http]an HTTP route
#[route_parameter_value]a route parameter type
#[provides_route_parameter]a route parameter binder
#[handles_middleware_attribute]a middleware
#[middleware]adding middleware to a route
#[renders_view]a named view

Background work and WebSockets

AttributeWhat it's for
#[service]a background service
#[scheduled_with_tick_timer]a scheduled task
#[websocket_session]a WebSocket session
#[build_for_session]how a WebSocket session is built
#[websocket_message]a WebSocket request, response, or notification

The database

AttributeWhat it's for
#[postgres_database]the application's database
#[model]a table
#[eager_load]a shape: a model with related rows

Inside a model, #[column] marks every field, with primary_key, unique, name, precision and scale, minimum, byte_length, or default. #[foreign_key] decides what happens to a Key field when its row goes away, and #[index] indexes a single field. On the model itself, #[primary_key], #[unique], and #[index] span several fields, and #[has_many] and #[has_one] declare relations. Inside a shape, #[base] marks the model and #[relation] each related row. See Database, Requests, Responses, and the Queries cheat sheet.

Signing in and sessions

AttributeWhat it's for
#[issues_tokens]this application issues signed tokens
#[issues_sessions]browser sessions
#[consumes_sessions]sessions issued by another application
#[serves_session_endpoint]signing out, and refreshing shared sessions
#[infers_authenticated_user]who is making a request
#[infer_from_request]how the current user is found
#[oauth_client]this application as an OAuth or OpenID Connect client
#[serves_sign_in]sign-in start and callback routes
#[admits_sign_in]who may sign in
#[verifies_tokens_from_issuer]trusting another issuer's tokens

Being a provider

AttributeWhat it's for
#[admits_oauth_client]a client of this application's provider
#[issues_resource_tokens]a resource that access tokens are for
#[oauth_scope]a scope
#[serves_oidc_endpoint]a provider endpoint
#[provides_userinfo_claims]the claims userinfo answers with
#[exchanges_tokens_from]exchanging another issuer's tokens for your own

On parameters

AttributeWhat it's for
#[console_argument]a command line flag or argument
#[environment_variable]an environment variable
#[spiffe_http_client]an HTTP client with your service's identity
#[route_parameter]a part of the path
#[form_request]validated request data
#[authenticated_user]the current user
#[session]the browser's session
#[bearer_token]a verified access or ID token

The first three go on constructor parameters. The rest go on the parameters of a route, a middleware, a WebSocket session builder, or a user provider. Parameters without an attribute are recognized by their type: &Routes, &Views, AssetBag, Forwarder, &Request, Next, UploadedFiles, RequestBodyStream, &SpiffeId, and CancellationToken.