Reusing requests with REST Insight
Building a request in code is only one workflow. TTMSFNCRESTClient also pairs with a visual editor and with REST Insight, a standalone cross-platform HTTP client, so you can design and test a call interactively, save it, and load it back into your application at run time. This chapter covers the design-time editor, the save/load round-trip via LoadRequest, and turning a JSON response into a Delphi class.
The design-time editor
Drop a TTMSFNCRESTClient on a form, right-click it, and choose Open Editor to build and test the request visually — set the URL, method, headers, authorization, and body, then run it and preview the response without compiling. The editor is delivered as a separate design-time package (install the TMSFNCRESTClientEditorPkg project from the product folder) and depends on TMS FNC UI Pack.
Note
The component itself has no dependency on the editor or on the UI Pack. The editor is purely a design-time convenience; the runtime TTMSFNCRESTClient works on its own.
Saving and loading request definitions
Requests designed in REST Insight (or the editor) can be exported to a .json definition and loaded back into a client at run time. LoadRequest opens a dialog to pick that file and fills the Request — host, path, headers, authorization, and body — so you can keep request definitions outside your source and update them without recompiling.
procedure TForm1.LoadAndRun;
begin
{ LoadRequest opens a dialog to pick a .json request definition exported
from REST Insight or the design-time editor, and fills Request with it. }
TMSFNCRESTClient1.LoadRequest;
{ The loaded definition already carries host, path, headers and
authorization, so it can be executed straight away. }
TMSFNCRESTClient1.ExecuteRequestWithResultString(
procedure(AResponseString: string)
begin
Memo1.Lines.Text := AResponseString;
end);
end;
REST Insight runs on Windows (32- and 64-bit), macOS (Intel and Apple Silicon), and Ubuntu Linux, and was itself built with TMS FNC Core and TMS FNC UI Pack. See the REST Insight product page for the standalone tool.
Generating Delphi classes from a JSON response
When a request returns JSON, you can turn the response into a strongly-typed Delphi class instead of reading values by hand. The TTMSFNCJSONToClass helper (in FMX.TMSFNCPersistence.pas, part of TMS FNC Core) generates a class definition from a JSON sample, which you then populate from each response. This pairs well with the text result type and the JSON helpers in TTMSFNCUtils.
Load, run, and inspect together
The save/load workflow combines naturally with execution and inspection: load a saved definition, run it, and read the outcome in one flow.
procedure TForm1.LoadRunInspect;
begin
{ Load a request definition exported from REST Insight. }
TMSFNCRESTClient1.LoadRequest;
{ Run it and inspect status, size, and timing together. }
TMSFNCRESTClient1.ExecuteRequestWithResultString(
procedure(AResponseString: string)
var
LExecuted: TTMSFNCRESTClientExecutedRequest;
begin
LExecuted := TMSFNCRESTClient1.GetExecutedRequestByURL(TMSFNCRESTClient1.Request.URL);
if Assigned(LExecuted) then
Memo1.Lines.Add(Format('HTTP %d, %d bytes, %d ms',
[LExecuted.Response.ResponseCode,
LExecuted.Response.ResponseSize,
LExecuted.Response.ResponseTime]));
end);
end;
Common mistakes
- Expecting the editor at run time. The visual editor is design-time only. At run time, use
LoadRequest(or build the request in code) — there is no runtime editor window. - Shipping without the loaded file. If you rely on
LoadRequest, deploy the.jsondefinition alongside the application, or the load dialog has nothing to open.