Skip to content

Attributes Reference

A compact cheat-sheet of MARS attributes. See Server ▸ Attributes for explanations and examples. Unless noted, attributes are in MARS.Core.Attributes.

Routing & verbs

AttributeTargetPurpose
[Path('seg')]class, methodRoute segment (supports {token} and {*}).
[GET] [POST] [PUT] [DELETE] [PATCH] [HEAD] [OPTIONS]methodHTTP verb.

Content negotiation

AttributeTargetPurpose
[Produces('type')]method, writerResponse media type(s).
[Consumes('type')]method, readerAccepted request body media type(s).
[Encoding('UTF8')]methodText encoding for serialization.

Parameter binding (on method parameters)

AttributeSource
[PathParam('name')]URL path token (always required).
[QueryParam('name')]Query string.
[FormParam('name')]Form field (urlencoded / multipart).
[HeaderParam('name')]Request header.
[CookieParam('name')]Cookie.
[BodyParam]Entire request body (deserialized).
[PathParams] [QueryParams] [Headers] [Cookies] [FormParams]All values of that kind as a collection.
[Required]Marks a bound parameter mandatory.

Injection

AttributeTargetPurpose
[Context]field, property, parameterInject a framework/custom service.
[EngineParam('Name', Default)]field, property, parameterValue from engine parameters.
[ApplicationParam('Name', Default)]field, property, parameterValue from application parameters.
[EngineParamFunc] [ApplicationParamFunc]as aboveInject a TConfigParamFunc for dynamic lookup.

Security

AttributeTargetPurpose
[PermitAll]resource, methodAllow everyone.
[DenyAll]resource, methodDeny everyone (highest priority).
[RolesAllowed('a','b')]resource, methodRequire any listed role.

Response shaping

AttributeTargetPurpose
[ContentType('type')]methodForce response Content-Type.
[CustomHeader('Name','Value')]methodAdd a fixed response header.
[IsReference]methodReturned object must not be freed by MARS.
[JSONP(True, 'callback', 'text/javascript')]methodWrap JSON as JSONP.

Lifecycle hooks (on resource methods)

AttributeWhen
[BeforeInvoke]Before the endpoint method runs.
[AfterInvoke]After it returns.
[InvokeError]When it raises.
[AfterContextCleanup]After injected context is freed.

Metadata & OpenAPI (MARS.Metadata.Attributes, OpenAPI units)

AttributeTargetPurpose
[MetaSummary('...')]resource, methodShort summary.
[MetaDescription('...')]resource, method, parameterLonger description.
[MetaVisible(False)]resource, methodHide from metadata/OpenAPI.
[OAPIDescription] [OAPIRequired] [OAPIPattern] [OAPIMinimum] [OAPIMaximum]record/class fieldJSON-schema hints.

JSON serialization (MARS.Core.JSON)

AttributeTargetPurpose
[JSONName('key')]fieldCustom JSON key.
[JSONSkip]fieldExclude from (de)serialization.
[JSONSkipEmptyValues] [JSONIncludeEmptyValues]field, resource, methodEmpty/null inclusion policy.

Data — FireDAC (MARS.Data.FireDAC.*)

AttributeTargetPurpose
[Connection('DEFNAME')]resource, field, parameterSelect FireDAC connection definition.
[SQLStatement('Name','SELECT …')]resourceDeclare a named SQL statement.

Web server (MARS.WebServer.Resources)

AttributeTargetPurpose
[RootFolder('path', AServeIndex)]resourceMap a TFileSystemResource to a disk folder.

Released under the Apache License 2.0.