TsgcWSAPIKeyManagerMethods › ExtractKeyFromQuery

ExtractKeyFromQuery Method

Parses the Validation.QueryParamName value out of a raw query string.

Syntax

function ExtractKeyFromQuery(const aQueryString: string): string;

Parameters

NameTypeDescription
aQueryStringconst stringRaw query string (may include a leading ?) or a full URL — anything after the first ? is parsed as name=value&….

Return Value

URL-decoded value of the configured parameter, or an empty string when the parameter is absent or empty. (string)

Remarks

Low-level parser used as a fallback inside IsRequestAuthorized when no header value is found. Reads the parameter named by Validation.QueryParamName (default api_key) from the supplied query string, honouring standard URL decoding (%XX, + as space). Useful when clients cannot set custom headers (CDN caches, <img> tags, server-side redirects). Prefer the header over the query-string form in production — query-string keys tend to leak into access logs and browser history.

Example

var
  vKey: string;
begin
  vKey := sgcWSAPIKeyManager1.ExtractKeyFromQuery(Connection.URL);
  if vKey = '' then
    vKey := sgcWSAPIKeyManager1.ExtractKeyFromHeaders(Connection.HeadersRequest.Text);
end;

Back to Methods