Skip to content

Components

The MARS client is component-based, so you can build a consumer visually. After installing the MARSClient.CoreDesign (and MARSClient.FireDACDesign) packages, the components appear on the MARS-Curiosity Client palette page.

The component tree

A typical form wires components like this:

TMARSNetClient        Client1     MARSEngineURL = 'http://localhost:8080/rest'
└ TMARSClientApplication  App1    Client = Client1; AppName = 'default'
  ├ TMARSClientToken      Token1   Application = App1
  └ TMARSClientResourceJSON Res1   Application = App1; Token = Token1; Resource = 'people'

At design time the components auto-discover their parents: dropping a TMARSClientApplication finds a client on the form; dropping a resource finds an application (and a token). You can always set the links explicitly in the Object Inspector.

Client — TMARSCustomClient

The transport. Use TMARSNetClient, TMARSHttpClient or TMARSIndyClient (see Overview). Key properties:

PropertyPurpose
MARSEngineURLBase server URL, including the engine BasePath (e.g. http://host:8080/rest).
ConnectTimeout, ReadTimeoutNetwork timeouts (ms).
AuthEndorsementHow the JWT is sent: AuthorizationBearer or Cookie.
ProxyConfigProxy host/port/credentials.
OnErrorCentral handler for failed requests.

Application — TMARSClientApplication

Represents the server-side application you are talking to.

PropertyPurpose
ClientThe transport component.
AppNameThe application's base-path name (e.g. default).
DefaultMediaTypeDefault Accept (default application/json).
DefaultContentTypeDefault request Content-Type.

Resources

All resource components descend from TMARSClientCustomResource and share these properties:

PropertyPurpose
ApplicationThe owning application component.
ResourceThe resource path segment (e.g. people).
PathParamsValuesTStringList of values substituted into the resource path.
QueryParamsTStringList of name=value query parameters.
CustomHeadersExtra request headers.
TokenA TMARSClientToken to authenticate with (optional).
SpecificClient / SpecificToken / SpecificURLOverrides that bypass Application/Token/path-building.
SpecificAccept / SpecificContentTypePer-resource media-type overrides.

The specialized resource types add convenience on top:

ComponentForAdds
TMARSClientResourceraw payloadsGETAsString, stream verbs
TMARSClientResourceJSONrecords/objectsResponse: TJSONValue, ResponseAs<T>, typed POST<R>
TMARSClientResourceStreambinaryResponse: TStream
TMARSClientResourceFormDatamultipart uploadsFormData: TArray<TFormParam>
TMARSClientResourceFormUrlEncodedurlencoded formsFormUrlEncoded parameters
TMARSClientResourceSSEserver-sent eventsOpen/Close, OnMessage
TMARSFDResource / TMARSFDDataSetResourceFireDAC datasetsdataset sync & deltas

Token — TMARSClientToken

Manages authentication for the resources that reference it.

MemberPurpose
UserName, PasswordCredentials to send on login.
AuthenticatePerform the login (POST to the token resource).
Token (read-only)The current JWT string.
IsVerified, AuthenticatedStatus flags.
UserRoles, Claims, ExpirationDecoded token info.
SaveToFile / LoadFromFilePersist the token between sessions.

See Authentication.

Setting it up in code

Everything you set in the Object Inspector you can also do in code (handy for unit tests and services):

pascal
LClient := TMARSNetClient.Create(Self);
LClient.MARSEngineURL := 'http://localhost:8080/rest';

LApp := TMARSClientApplication.Create(Self);
LApp.Client := LClient;
LApp.AppName := 'default';

LRes := TMARSClientResourceJSON.Create(Self);
LRes.Application := LApp;
LRes.Resource := 'people';

Because the components have an owner (Self), they are freed with the form — no manual cleanup needed.

Released under the Apache License 2.0.