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] [QUERY]methodHTTP verb (QUERY: safe method with a body, bind it with [BodyParam]).

Content negotiation ​

AttributeTargetPurpose
[Produces('type')]method, writerResponse media type(s).
[Consumes('type')]method, readerAccepted request body media type(s).
[Encoding('UTF8')]method, resourceText encoding for serialization: UTF8 (default), ANSI, ASCII, Unicode, BigEndianUnicode, UTF7, Default.

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.
[OAPISummary] [OAPIDescription]resource, method, type, field, parameterText used in the OpenAPI document only (overrides [Meta…]).
[OAPIRequired] [OAPIDefault] [OAPIPattern] [OAPIMinimum] [OAPIMaximum] [OAPIMinLength] [OAPIMaxLength]record/class field, parameterJSON-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', AIncludeSubFolders)]resourceMap a TFileSystemResource to a disk folder; AIncludeSubFolders = False serves the root folder only.
[DirectoryListing(False)]resourceDisable the HTML listing of directories without an index file (404 instead).
[DotSegments]resourceAccept . and .. in the paths of a TFileSystemResource, as long as they stay inside the root folder (default: 404).
[Exclude('mask')]resourceNever serve files whose full path matches the mask (case-insensitive, repeatable; 404).
[Include('mask')]resourceServe only files whose full path matches one of the masks (repeatable; exclusions still win).

Released under the Apache License 2.0.