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
| Attribute | Target | Purpose |
|---|---|---|
[Path('seg')] | class, method | Route segment (supports {token} and {*}). |
[GET] [POST] [PUT] [DELETE] [PATCH] [HEAD] [OPTIONS] [QUERY] | method | HTTP verb (QUERY: safe method with a body, bind it with [BodyParam]). |
Content negotiation
| Attribute | Target | Purpose |
|---|---|---|
[Produces('type')] | method, writer | Response media type(s). |
[Consumes('type')] | method, reader | Accepted request body media type(s). |
[Encoding('UTF8')] | method, resource | Text encoding for serialization: UTF8 (default), ANSI, ASCII, Unicode, BigEndianUnicode, UTF7, Default. |
Parameter binding (on method parameters)
| Attribute | Source |
|---|---|
[PathParam('name')] | URL path token (always required). |
[QueryParam('name')] | Query string. |
[FormParam('name')] | Form field (urlencoded / multipart). |
[HeaderParam('name')] | Request header (also on a field or property of the resource: every method). |
[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: 400 when missing. |
Injection
| Attribute | Target | Purpose |
|---|---|---|
[Context] | field, property, parameter | Inject a framework/custom service. |
[EngineParam('Name', Default)] | field, property, parameter | Value from engine parameters. |
[ApplicationParam('Name', Default)] | field, property, parameter | Value from application parameters. |
[EngineParamFunc] [ApplicationParamFunc] | as above | Inject a TConfigParamFunc for dynamic lookup. |
Security
| Attribute | Target | Purpose |
|---|---|---|
[PermitAll] | resource, method | Allow everyone (with roles on the endpoint: any valid token). |
[Authenticated] | resource, method | Require a valid token, any role. |
[DenyAll] | resource, method | Deny everyone (highest priority). |
[RolesAllowed('a','b')] | resource, method | Require any listed role. |
Response shaping
| Attribute | Target | Purpose |
|---|---|---|
[ContentType('type')] | method | Force response Content-Type. |
[CustomHeader('Name','Value')] | method | Add a fixed response header. |
[IsReference] | method | Returned object must not be freed by MARS. |
[JSONP(True, 'callback', 'text/javascript')] | method | Wrap JSON as JSONP. |
Lifecycle hooks (on resource methods)
| Attribute | When |
|---|---|
[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)
[MetaHeader('X-Api-Key', 'description', ARequired)] on a method or a resource (several allowed): a request header in the OpenAPI document, for the documentation only (the code or a middleware reads it by itself). [HeaderParam], [QueryParam] and [CookieParam] on fields and properties of a resource are parameters of all its operations. See OpenAPI ▸ Request headers.
[MetaResult(TypeInfo(TType), AIsArray, 'description')] (or by qualified name, [MetaResult('Unit.TType')]) on a method: the shape of its result in the JSON media types of the OpenAPI document, i.e. the rows of a dataset. See OpenAPI ▸ Datasets and the shape of a result.
| Attribute | Target | Purpose |
|---|---|---|
[MetaSummary('...')] | resource, method | Short summary. |
[MetaDescription('...')] | resource, method, parameter | Longer description. |
[MetaVisible(False)] | resource, method | Hide from metadata/OpenAPI. |
[OAPISummary] [OAPIDescription] | resource, method, type, field, parameter | Text used in the OpenAPI document only (overrides [Meta…]). |
[OAPIRequired] [OAPIDefault] [OAPIPattern] [OAPIMinimum] [OAPIMaximum] [OAPIMinLength] [OAPIMaxLength] | record/class field, parameter | JSON-schema hints. |
JSON serialization (MARS.Core.JSON)
| Attribute | Target | Purpose |
|---|---|---|
[JSONName('key')] | field | Custom JSON key. |
[JSONSkip] | field | Exclude from (de)serialization. |
[JSONSkipEmptyValues] [JSONIncludeEmptyValues] | field, resource, method | Empty/null inclusion policy. |
[JSONDateIsUTC] [JSONDateIsUTC(False)] | resource, method | Dates as UTC (...Z) or as local times with their offset, whatever JSON.DateIsUTC says. See Serialization. |
Data — FireDAC (MARS.Data.FireDAC.*)
| Attribute | Target | Purpose |
|---|---|---|
[Connection('DEFNAME')] | resource, field, parameter | Select FireDAC connection definition. |
[SQLStatement('Name','SELECT …')] | resource | Declare a named SQL statement. |
Web server (MARS.WebServer.Resources)
| Attribute | Target | Purpose |
|---|---|---|
[RootFolder('path', AIncludeSubFolders)] | resource | Map a TFileSystemResource to a disk folder; AIncludeSubFolders = False serves the root folder only. |
[DirectoryListing(False)] | resource | Disable the HTML listing of directories without an index file (404 instead). |
[DotSegments] | resource | Accept . and .. in the paths of a TFileSystemResource, as long as they stay inside the root folder (default: 404). |
[Exclude('mask')] | resource | Never serve files whose full path matches the mask (case-insensitive, repeatable; 404). |
[Include('mask')] | resource | Serve only files whose full path matches one of the masks (repeatable; exclusions still win). |
