delphimvcframework/sources/MVCFramework.RESTClient.pas

1087 lines
34 KiB
ObjectPascal
Raw Normal View History

// ***************************************************************************
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
// Collaborators on this file:
// Jo<4A>o Ant<6E>nio Duarte (https://github.com/joaoduarte19)
//
// ***************************************************************************
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// *************************************************************************** }
2013-10-30 00:48:23 +01:00
unit MVCFramework.RESTClient;
interface
uses
System.Classes,
2020-09-08 03:21:28 +02:00
System.SysUtils,
System.Net.HttpClient,
System.Net.Mime,
System.Net.URLClient,
System.Generics.Collections,
System.Rtti,
System.TypInfo,
MVCFramework.Commons,
MVCFramework.RESTClient.Indy,
2020-08-09 02:18:36 +02:00
MVCFramework.RESTClient.Intf,
MVCFramework.Serializer.Intf,
2020-08-09 02:18:36 +02:00
MVCFramework.Serializer.Commons,
2020-09-08 03:21:28 +02:00
Data.DB;
{ REST.Client }
{ MVCFramework.JSONRPC.Client }
2013-10-30 00:48:23 +01:00
type
/// <summary>
/// Alias for the Indy-based TRESTClient. The implementation of TRESTClient has been discontinued, it remains for
/// compatibility only.
/// </summary>
TRESTClient = MVCFramework.RESTClient.Indy.TRESTClient deprecated
'Moved to the MVCFramework.RESTClient.Indy unit. It is highly recommended to migrate to the TMVCRESTClient implementation.';
IRESTResponse = MVCFramework.RESTClient.Indy.IRESTResponse deprecated
'Moved to the MVCFramework.RESTClient.Indy unit. It is highly recommended to migrate to the TMVCRESTClient implementation.';
/// <summary>
/// Provides access to delphi RESTClient library types without the need to use the REST.Types unit.
/// </summary>
TCookie = System.Net.HttpClient.TCookie;
TCookies = System.Net.HttpClient.TCookies;
2020-09-08 03:21:28 +02:00
{$IF defined(TOKYOORBETTER)}
2020-08-26 22:13:18 +02:00
THTTPSecureProtocol = System.Net.HttpClient.THTTPSecureProtocol;
THTTPSecureProtocols = System.Net.HttpClient.THTTPSecureProtocols;
2020-09-08 03:21:28 +02:00
{$ENDIF}
TMVCRESTClient = class(TInterfacedObject, IMVCRESTClient)
private
2020-09-08 03:21:28 +02:00
fHTTPClient: THTTPClient;
fBaseURL: string;
fResource: string;
fProxySettings: TProxySettings;
fHeaders: TList<TNetHeader>;
fPathParams: TList<TNameValuePair>;
fQueryStringParams: TList<TNameValuePair>;
fRawBody: TStringStream;
fBodyURLEncoded: TList<TNameValuePair>;
fBodyFormData: TMultipartFormData;
fSerializer: IMVCSerializer;
2020-09-08 03:21:28 +02:00
fRttiContext: TRttiContext;
function GetBodyFormData: TMultipartFormData;
function GetContentTypeCharset(const aContentType: string): string;
2020-08-09 02:18:36 +02:00
function ObjectIsList(aObject: TObject): Boolean;
function SerializeObject(aObject: TObject): string;
2020-09-08 03:21:28 +02:00
procedure SetContentType(const aContentType: string);
function GetFullURL: string;
procedure DoApplyPathParams(var aURL: string);
procedure DoApplyQueryParams(var aURL: string);
procedure DoApplyHeaders;
procedure DoEncodeURL(var aURL: string);
function ExecuteRequest(const aMethod: TMVCHTTPMethodType): IMVCRESTResponse;
2013-10-30 00:48:23 +01:00
public
constructor Create;
2013-10-30 00:48:23 +01:00
destructor Destroy; override;
class function New: IMVCRESTClient;
{ IMVCRESTClient }
2020-08-14 00:43:25 +02:00
function BaseURL(const aBaseURL: string): IMVCRESTClient; overload;
function BaseURL(const aHost: string; const aPort: Integer): IMVCRESTClient; overload;
function BaseURL: string; overload;
function ProxyServer(const aProxyServer: string): IMVCRESTClient; overload;
function ProxyServer: string; overload;
function ProxyPort(const aProxyPort: Integer): IMVCRESTClient; overload;
function ProxyPort: Integer; overload;
function ProxyUsername(const aProxyUsername: string): IMVCRESTClient; overload;
function ProxyUsername: string; overload;
function ProxyPassword(const aProxyPassword: string): IMVCRESTClient; overload;
function ProxyPassword: string; overload;
2020-09-08 03:21:28 +02:00
// {$IF defined(TOKYOORBETTER)}
2020-08-26 22:13:18 +02:00
function SecureProtocols(const aSecureProtocols: THTTPSecureProtocols): IMVCRESTClient; overload;
function SecureProtocols: THTTPSecureProtocols; overload;
2020-09-08 03:21:28 +02:00
// {$ENDIF}
2020-08-26 22:13:18 +02:00
function UserAgent(const aUserAgent: string): IMVCRESTClient; overload;
function UserAgent: string; overload;
/// <summary>
2020-09-08 03:21:28 +02:00
/// Clears all parameters, except authorization headers. This method is executed after each request is completed.
/// </summary>
function ClearAllParams: IMVCRESTClient;
/// <summary>
/// Connection timeout in milliseconds to be used for the requests.
/// </summary>
function ConnectTimeout(const aConnectTimeout: Integer): IMVCRESTClient; overload;
function ConnectTimeout: Integer; overload;
/// <summary>
/// Response reading timeout in milliseconds to be used for the requests.
/// </summary>
function ReadTimeout(const aReadTimeout: Integer): IMVCRESTClient; overload;
function ReadTimeout: Integer; overload;
/// <summary>
/// Add basic authorization header. Authorization = Basic &lt;Username:Password&gt; (encoded in Base64)
/// </summary>
function SetBasicAuthorization(const aUsername, aPassword: string): IMVCRESTClient;
/// <summary>
/// Add bearer authorization header. Authorization = Bearer &lt;Token&gt;
/// </summary>
function SetBearerAuthorization(const aToken: string): IMVCRESTClient;
/// <summary>
/// Add a header.
/// </summary>
/// <param name="aName">
/// Header name
/// </param>
/// <param name="aValue">
/// Header value
/// </param>
/// <param name="aDoNotEncode">
/// Indicates whether the value of this header should be used as is (True), or encoded by the component (False)
/// </param>
2020-09-08 03:21:28 +02:00
function AddHeader(const aName, aValue: string): IMVCRESTClient; overload;
function HeaderValue(const aName: string): string;
/// <summary>
/// Clears all headers.
/// </summary>
function ClearHeaders: IMVCRESTClient;
function AllowCookies(const aAllowCookies: Boolean): IMVCRESTClient; overload;
function AllowCookies: Boolean; overload;
/// <summary>
/// Add a cookie header.
/// </summary>
function AddCookie(const aName, aValue: string): IMVCRESTClient;
/// <summary>
2020-09-08 03:21:28 +02:00
/// Clear all cookie headers.
/// </summary>
function ClearCookies: IMVCRESTClient;
/// <summary>
/// Add a URL segment parameter. The parameters of your url path may be enclosed in braces or in
/// parentheses starting with a money sign. <c>/api/{param1}/($param2)</c>
/// </summary>
/// <param name="aName">
/// Parameter name
/// </param>
/// <param name="aValue">
/// Parameter value
/// </param>
function AddPathParam(const aName, aValue: string): IMVCRESTClient; overload;
function AddPathParam(const aName: string; aValue: Integer): IMVCRESTClient; overload;
function AddPathParam(const aName: string; aValue: Int64): IMVCRESTClient; overload;
function AddPathParam(const aName: string; aValue: TGUID): IMVCRESTClient; overload;
function AddPathParam(const aName: string; aValue: TDateTime): IMVCRESTClient; overload;
function AddPathParam(const aName: string; aValue: TDate): IMVCRESTClient; overload;
function AddPathParam(const aName: string; aValue: TTime): IMVCRESTClient; overload;
function AddPathParam(const aName: string; aValue: Double): IMVCRESTClient; overload;
function ClearPathParams: IMVCRESTClient;
/// <summary>
/// Add a QueryString parameter. <c>/api/person?para1=value&amp;param2=value</c>
/// </summary>
function AddQueryStringParam(const aName, aValue: string): IMVCRESTClient; overload;
function AddQueryStringParam(const aName: string; aValue: Integer): IMVCRESTClient; overload;
function AddQueryStringParam(const aName: string; aValue: Int64): IMVCRESTClient; overload;
function AddQueryStringParam(const aName: string; aValue: TGUID): IMVCRESTClient; overload;
function AddQueryStringParam(const aName: string; aValue: TDateTime): IMVCRESTClient; overload;
function AddQueryStringParam(const aName: string; aValue: TDate): IMVCRESTClient; overload;
function AddQueryStringParam(const aName: string; aValue: TTime): IMVCRESTClient; overload;
function AddQueryStringParam(const aName: string; aValue: Double): IMVCRESTClient; overload;
function ClearQueryParams: IMVCRESTClient;
function Accept(const aAccept: string): IMVCRESTClient; overload;
function Accept: string; overload;
function AcceptCharset(const aAcceptCharset: string): IMVCRESTClient; overload;
function AcceptCharset: string; overload;
function AcceptEncoding(const aAcceptEncoding: string): IMVCRESTClient; overload;
function AcceptEncoding: string; overload;
function HandleRedirects(const aHandleRedirects: Boolean): IMVCRESTClient; overload;
function HandleRedirects: Boolean; overload;
2020-09-08 03:21:28 +02:00
function MaxRedirects(const aMaxRedirects: Integer): IMVCRESTClient; overload;
function MaxRedirects: Integer; overload;
function Resource(const aResource: string): IMVCRESTClient; overload;
function Resource: string; overload;
/// <summary>
/// Add a body to the requisition.
/// </summary>
/// <param name="aBody">
/// Body in string format.
/// </param>
/// <param name="aContentType">
/// Body content type.
/// </param>
2020-09-08 03:21:28 +02:00
function AddBody(const aBody: string; const aContentType: string = ''): IMVCRESTClient; overload;
/// <summary>
/// Add a body to the requisition
/// </summary>
/// <param name="aBodyStream">
/// Body in Stream format
/// </param>
/// <param name="aContentType">
/// Body content type
/// </param>
/// <param name="aOwnsStream">
/// If OwnsStream is true, Stream will be destroyed by IMVCRESTClient.
/// </param>
2020-09-08 03:21:28 +02:00
function AddBody(aBodyStream: TStream; const aOwnsStream: Boolean = True;
const aContentType: string = ''): IMVCRESTClient; overload;
/// <summary>
/// Add a body to the requisition
/// </summary>
/// <param name="aBodyObject">
/// Body in Object format. The object will be serialized to a JSON string.
/// </param>
/// <param name="aOwnsObject">
/// If OwnsObject is true, BodyObject will be destroyed by IMVCRESTClient.
/// </param>
function AddBody(aBodyObject: TObject; const aOwnsObject: Boolean = True): IMVCRESTClient; overload;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Adds a file as the request body. Several files can be added in the same request. In this case the request
/// will be of the multipart/form-data type
/// </summary>
/// <param name="aName">
/// Field name
/// </param>
/// <param name="aFileName">
/// File path
/// </param>
/// <param name="aContentType">
/// File content type
/// </param>
2020-08-28 23:21:27 +02:00
function AddFile(const aName, aFileName: string; const aContentType: string = ''): IMVCRESTClient; overload;
function AddFile(const aFileName: string; const aContentType: string = ''): IMVCRESTClient; overload;
2020-09-08 03:21:28 +02:00
function AddBodyFieldFormData(const aName, aValue: string): IMVCRESTClient; overload;
function AddBodyFieldFormData(const aName: string; aStreamValue: TStream;
const aContentType: string = ''): IMVCRESTClient; overload;
/// <summary>
/// Add a field to the x-www-form-urlencoded body. You must set ContentType to application/x-www-form-urlencoded
/// </summary>
function AddBodyFieldURLEncoded(const aName, aValue: string): IMVCRESTClient;
function ClearBody: IMVCRESTClient;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Executes the next request asynchronously.
/// </summary>
/// <param name="aCompletionHandler">
/// An anonymous method that will be run after the execution completed.
/// </param>
/// <param name="aSynchronized">
/// Specifies if aCompletioHandler will be run in the main thread's (True) or execution thread's (False) context.
/// </param>
/// <param name="aCompletionHandlerWithError">
/// An anonymous method that will be run if an exception is raised during execution.
/// </param>
function Async(aCompletionHandler: TProc<IMVCRESTResponse>; aCompletionHandlerWithError: TProc<Exception> = nil;
const aSynchronized: Boolean = False): IMVCRESTClient;
/// <summary>
/// Execute a Get request.
/// </summary>
function Get(const aResource: string): IMVCRESTResponse; overload;
function Get: IMVCRESTResponse; overload;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Execute a Post request.
/// </summary>
2020-09-08 03:21:28 +02:00
/// <param name="aResource">
/// Resource path
/// </param>
/// <param name="aBody">
/// Object to be serialized. It can be a simple object or a list of objects (TObjectList &lt;T&gt;)
/// </param>
/// <param name="aOwnsBody">
/// If OwnsBody is true, Body will be destroyed by IMVCRESTClient. <br />
/// </param>
function Post(const aResource: string; aBody: TObject; const aOwnsBody: Boolean = True): IMVCRESTResponse; overload;
function Post(const aResource: string; const aBody: string = ''; const aDoNotEncode: Boolean = False;
const aContentType: string = TMVCMediaType.APPLICATION_JSON): IMVCRESTResponse; overload;
function Post: IMVCRESTResponse; overload;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Execute a Patch request.
/// </summary>
function Patch(const aResource: string; aBody: TObject;
const aOwnsBody: Boolean = True): IMVCRESTResponse; overload;
function Patch(const aResource: string; const aBody: string = ''; const aDoNotEncode: Boolean = False;
const aContentType: string = TMVCMediaType.APPLICATION_JSON): IMVCRESTResponse; overload;
function Patch: IMVCRESTResponse; overload;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Execute a Put request.
/// </summary>
function Put(const aResource: string; aBody: TObject; const aOwnsBody: Boolean = True): IMVCRESTResponse; overload;
function Put(const aResource: string; const aBody: string = ''; const aDoNotEncode: Boolean = False;
const aContentType: string = TMVCMediaType.APPLICATION_JSON): IMVCRESTResponse; overload;
function Put: IMVCRESTResponse; overload;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Execute a Delete request.
/// </summary>
function Delete(const aResource: string): IMVCRESTResponse; overload;
function Delete: IMVCRESTResponse; overload;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Serialize the current dataset record and execute a POST request.
/// </summary>
2020-08-09 02:18:36 +02:00
function DataSetInsert(const aResource: string; aDataSet: TDataSet; const aIgnoredFields: TMVCIgnoredList = [];
const aNameCase: TMVCNameCase = ncAsIs): IMVCRESTResponse;
/// <summary>
/// Serialize the current dataset record and execute a PUT request.
/// </summary>
2020-09-08 03:21:28 +02:00
function DataSetUpdate(const aResource, aKeyValue: string; aDataSet: TDataSet;
const aIgnoredFields: TMVCIgnoredList = []; const aNameCase: TMVCNameCase = ncAsIs): IMVCRESTResponse;
/// <summary>
/// Delete the current dataset record by executing a delete request.
/// </summary>
function DataSetDelete(const aResource, aKeyValue: string): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
/// <summary>
/// Register a custom serializer to the RESTClient serializer.
/// </summary>
function RegisterTypeSerializer(const aTypeInfo: PTypeInfo; aInstance: IMVCTypeSerializer): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
end;
implementation
2015-12-18 20:59:40 +01:00
uses
2020-09-08 03:21:28 +02:00
System.NetConsts,
2020-08-09 02:18:36 +02:00
System.NetEncoding,
2020-09-08 03:21:28 +02:00
MVCFramework.Serializer.JsonDataObjects;
const
PATH_UNSAFE_CHARS: TURLEncoding.TUnsafeChars = [Ord('"'), Ord('<'), Ord('>'), Ord('^'), Ord('`'), Ord('{'),
Ord('}'), Ord('|'), Ord('/'), Ord('\'), Ord('?'), Ord('#'), Ord('+'), Ord('.')];
2020-09-08 03:21:28 +02:00
QUERY_NAME_UNSAFE_CHARS: TURLEncoding.TUnsafeChars = [Ord('"'), Ord(''''), Ord(':'), Ord(';'), Ord('<'), Ord('='),
Ord('>'), Ord('@'), Ord('['), Ord(']'), Ord('^'), Ord('`'), Ord('{'), Ord('}'), Ord('|'), Ord('/'), Ord('\'),
Ord('?'), Ord('#'), Ord('&'), Ord('!'), Ord('$'), Ord('('), Ord(')'), Ord(','), Ord('~'), Ord(' '), Ord('*'),
Ord('+')];
{ TMVCRESTClient }
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Accept: string;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Accept(const aAccept: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHTTPClient.Accept := aAccept;
2015-12-18 20:59:40 +01:00
end;
function TMVCRESTClient.AcceptCharset: string;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.AcceptCharSet;
2015-12-18 20:59:40 +01:00
end;
function TMVCRESTClient.AcceptCharset(const aAcceptCharset: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fHTTPClient.AcceptCharSet := aAcceptCharset;
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AcceptEncoding(const aAcceptEncoding: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHTTPClient.AcceptEncoding := aAcceptEncoding;
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AcceptEncoding: string;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.AcceptEncoding;
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddBody(const aBody: string; const aContentType: string): IMVCRESTClient;
var
2020-09-08 03:21:28 +02:00
lContentCharset: string;
lEncoding: TEncoding;
lBytes: TArray<Byte>;
2015-12-18 20:59:40 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
SetContentType(aContentType);
2020-09-08 03:21:28 +02:00
lContentCharset := GetContentTypeCharset(aContentType);
if lContentCharset.IsEmpty then
begin
lContentCharset := TMVCCharSet.UTF_8;
end;
lEncoding := TEncoding.GetEncoding(lContentCharset);
2020-09-08 03:21:28 +02:00
fRawBody.Clear;
lBytes := TEncoding.Convert(TEncoding.Default, lEncoding, TEncoding.Default.GetBytes(aBody));
fRawBody.WriteData(lBytes, Length(lBytes));
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddBody(aBodyStream: TStream; const aOwnsStream: Boolean;
const aContentType: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
Result := Self;
2020-08-09 02:18:36 +02:00
2020-09-08 03:21:28 +02:00
Assert(ABodyStream is TStringStream);
SetContentType(aContentType);
2020-08-09 02:18:36 +02:00
2020-09-08 03:21:28 +02:00
fRawBody.Clear;
fRawBody.CopyFrom(aBodyStream, 0);
if aOwnsStream then
aBodyStream.Free;
end;
function TMVCRESTClient.AddBody(aBodyObject: TObject; const aOwnsObject: Boolean): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := AddBody(SerializeObject(aBodyObject), TMVCMediaType.APPLICATION_JSON);
2020-08-09 02:18:36 +02:00
if aOwnsObject then
aBodyObject.Free;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddBodyFieldFormData(const aName, aValue: string): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
GetBodyFormData.AddField(aName, aValue);
SetContentType(TMVCMediaType.MULTIPART_FORM_DATA);
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddBodyFieldFormData(const aName: string; aStreamValue: TStream;
const aContentType: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-08-09 02:18:36 +02:00
Result := Self;
2020-09-08 03:21:28 +02:00
GetBodyFormData.AddStream(aName, aStreamValue, aContentType);
SetContentType(TMVCMediaType.MULTIPART_FORM_DATA);
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddBodyFieldURLEncoded(const aName, aValue: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fBodyURLEncoded.Add(TNameValuePair.Create(aName, aValue));
SetContentType(TMVCMediaType.APPLICATION_FORM_URLENCODED);
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddCookie(const aName, aValue: string): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddFile(const aFileName, aContentType: string): IMVCRESTClient;
begin
Result := AddFile('file', aFileName, aContentType);
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddFile(const aName, aFileName, aContentType: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
GetBodyFormData.AddFile(aName, aFileName, aContentType);
SetContentType(TMVCMediaType.MULTIPART_FORM_DATA);
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddHeader(const aName, aValue: string): IMVCRESTClient;
2014-04-10 13:56:23 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHeaders.Add(TNetHeader.Create(aName, aValue));
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddPathParam(const aName: string; aValue: Double): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-08-09 02:18:36 +02:00
Result := AddPathParam(aName, aValue.ToString);
2015-12-18 20:59:40 +01:00
end;
function TMVCRESTClient.AddPathParam(const aName, aValue: string): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fPathParams.Add(TNameValuePair.Create(aName, aValue));
2014-04-10 13:56:23 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddPathParam(const aName: string; aValue: TDate): IMVCRESTClient;
2014-04-10 13:56:23 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := AddPathParam(aName, DateToISODate(aValue));
2014-04-10 13:56:23 +02:00
end;
function TMVCRESTClient.AddPathParam(const aName: string; aValue: TTime): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-08-09 02:18:36 +02:00
Result := AddPathParam(aName, TimeToISOTime(aValue));
2015-12-18 20:59:40 +01:00
end;
function TMVCRESTClient.AddPathParam(const aName: string; aValue: TDateTime): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-08-09 02:18:36 +02:00
Result := AddPathParam(aName, DateTimeToISOTimeStamp(aValue));
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddPathParam(const aName: string; aValue: Int64): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := AddPathParam(aName, aValue.ToString);
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddPathParam(const aName: string; aValue: TGUID): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := AddPathParam(aName, aValue.ToString);
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddPathParam(const aName: string; aValue: Integer): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := AddPathParam(aName, aValue.ToString);
2013-10-30 00:48:23 +01:00
end;
function TMVCRESTClient.AddQueryStringParam(const aName: string; aValue: Double): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := AddPathParam(aName, aValue.ToString);
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddQueryStringParam(const aName: string; aValue: TTime): IMVCRESTClient;
begin
2020-09-08 03:21:28 +02:00
Result := AddQueryStringParam(aName, TimeToISOTime(aValue));
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddQueryStringParam(const aName: string; aValue: TDate): IMVCRESTClient;
begin
2020-09-08 03:21:28 +02:00
Result := AddQueryStringParam(aName, DateToISODate(aValue));
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddQueryStringParam(const aName: string; aValue: TDateTime): IMVCRESTClient;
begin
2020-09-08 03:21:28 +02:00
Result := AddQueryStringParam(aName, DateTimeToISOTimeStamp(aValue));
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddQueryStringParam(const aName: string; aValue: TGUID): IMVCRESTClient;
begin
2020-09-08 03:21:28 +02:00
Result := AddQueryStringParam(aName, aValue.ToString);
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AddQueryStringParam(const aName: string; aValue: Int64): IMVCRESTClient;
begin
2020-09-08 03:21:28 +02:00
Result := AddQueryStringParam(aName, aValue.ToString);
end;
function TMVCRESTClient.AddQueryStringParam(const aName, aValue: string): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fQueryStringParams.Add(TNameValuePair.Create(aName, aValue));
2013-10-30 00:48:23 +01:00
end;
function TMVCRESTClient.AddQueryStringParam(const aName: string; aValue: Integer): IMVCRESTClient;
begin
2020-08-09 02:18:36 +02:00
Result := AddQueryStringParam(aName, aValue.ToString);
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AllowCookies: Boolean;
2015-12-22 12:17:13 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.AllowCookies;
2015-12-22 12:17:13 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.AllowCookies(const aAllowCookies: Boolean): IMVCRESTClient;
2015-12-22 12:17:13 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHTTPClient.AllowCookies := aAllowCookies;
2015-12-22 12:17:13 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Async(aCompletionHandler: TProc<IMVCRESTResponse>;
aCompletionHandlerWithError: TProc<Exception>; const aSynchronized: Boolean): IMVCRESTClient;
begin
2020-09-08 03:21:28 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.BaseURL(const aBaseURL: string): IMVCRESTClient;
begin
Result := Self;
2020-08-20 23:35:28 +02:00
2020-09-08 03:21:28 +02:00
fBaseURL := aBaseURL;
if not fBaseURL.Contains('://') then
fBaseURL := 'http://' + fBaseURL;
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.BaseURL(const aHost: string; const aPort: Integer): IMVCRESTClient;
begin
Result := BaseURL(aHost + ':' + aPort.ToString);
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.BaseURL: string;
begin
Result := fBaseURL;
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ClearAllParams: IMVCRESTClient;
2020-08-09 02:18:36 +02:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
ClearHeaders;
ClearPathParams;
ClearQueryParams;
ClearBody;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ClearBody: IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
fRawBody.Clear;
if Assigned(fBodyFormData) then
FreeAndNil(fBodyFormData);
fBodyURLEncoded.Clear;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ClearCookies: IMVCRESTClient;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
fHTTPClient.CookieManager.Clear;
2013-10-30 00:48:23 +01:00
end;
function TMVCRESTClient.ClearHeaders: IMVCRESTClient;
2014-03-24 17:37:08 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fHeaders.Clear;
2014-03-24 17:37:08 +01:00
end;
function TMVCRESTClient.ClearPathParams: IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fPathParams.Clear;
2013-10-30 00:48:23 +01:00
end;
function TMVCRESTClient.ClearQueryParams: IMVCRESTClient;
2020-08-09 02:18:36 +02:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fQueryStringParams.Clear;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ConnectTimeout: Integer;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.ConnectionTimeout;
2020-08-20 23:35:28 +02:00
end;
function TMVCRESTClient.ConnectTimeout(const aConnectTimeout: Integer): IMVCRESTClient;
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fHTTPClient.ConnectionTimeout := aConnectTimeout;
2020-08-09 02:18:36 +02:00
end;
constructor TMVCRESTClient.Create;
2015-12-22 12:17:13 +01:00
begin
inherited Create;
2015-12-22 12:17:13 +01:00
2020-09-08 03:21:28 +02:00
fHTTPClient := THTTPClient.Create;
fBaseURL := '';
fResource := '';
fProxySettings := TProxySettings.Create('', 0);
fHeaders := TList<TNetHeader>.Create;
fPathParams := TList<TNameValuePair>.Create;
fQueryStringParams := TList<TNameValuePair>.Create;
fRawBody := TStringStream.Create;
fBodyURLEncoded := TList<TNameValuePair>.Create;
fBodyFormData := nil;
fSerializer := TMVCJsonDataObjectsSerializer.Create;
2020-08-09 02:18:36 +02:00
fRttiContext := TRttiContext.Create;
end;
function TMVCRESTClient.DataSetDelete(const aResource, aKeyValue: string): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.DataSetInsert(const aResource: string; aDataSet: TDataSet;
const aIgnoredFields: TMVCIgnoredList; const aNameCase: TMVCNameCase): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
2020-08-09 02:18:36 +02:00
end;
function TMVCRESTClient.DataSetUpdate(const aResource, aKeyValue: string; aDataSet: TDataSet;
const aIgnoredFields: TMVCIgnoredList; const aNameCase: TMVCNameCase): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Delete(const aResource: string): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Delete: IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
end;
destructor TMVCRESTClient.Destroy;
2013-11-11 12:23:49 +01:00
begin
2020-09-08 03:21:28 +02:00
FreeAndNil(fHTTPClient);
FreeAndNil(fHeaders);
FreeAndNil(fPathParams);
FreeAndNil(fQueryStringParams);
FreeAndNil(fBodyURLEncoded);
if Assigned(fBodyFormData) then
FreeAndNil(fBodyFormData);
fSerializer := nil;
2020-08-09 02:18:36 +02:00
fRttiContext.Free;
2020-09-08 03:21:28 +02:00
inherited;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
procedure TMVCRESTClient.DoApplyHeaders;
2020-08-20 23:35:28 +02:00
var
2020-09-08 03:21:28 +02:00
lHeader: TNetHeader;
begin
for lHeader in fHeaders do
begin
2020-09-08 03:21:28 +02:00
fHTTPClient.CustomHeaders[lHeader.Name] := lHeader.Value;
end;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
procedure TMVCRESTClient.DoApplyPathParams(var aURL: string);
var
lPathParam: TNameValuePair;
lReplace: string;
lEncodedParam: string;
begin
2020-09-08 03:21:28 +02:00
for lPathParam in fPathParams do
begin
lReplace := '{' + lPathParam.Name + '}';
lEncodedParam := TNetEncoding.URL.Encode(lPathParam.Value, PATH_UNSAFE_CHARS,
[TURLEncoding.TEncodeOption.EncodePercent]);
2020-09-08 03:21:28 +02:00
aURL := aURL.Replace(lReplace, lEncodedParam, [rfReplaceAll, rfIgnoreCase]);
end;
end;
2020-09-08 03:21:28 +02:00
procedure TMVCRESTClient.DoApplyQueryParams(var aURL: string);
var
lQueryParam: TNameValuePair;
lName: string;
lValue: string;
lConcat: string;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
for lQueryParam in fQueryStringParams do
begin
lName := TNetEncoding.URL.Encode(lQueryParam.Name, QUERY_NAME_UNSAFE_CHARS,
[TURLEncoding.TEncodeOption.EncodePercent]);
lValue := TNetEncoding.URL.EncodeForm(lQueryParam.Value);
2020-08-09 02:18:36 +02:00
2020-09-08 03:21:28 +02:00
if aURL.Contains('?') then
lConcat := '&'
else
lConcat := '?';
2020-09-08 03:21:28 +02:00
aURL := aURL + lConcat + lName + '=' + lValue;
end;
end;
2020-09-08 03:21:28 +02:00
procedure TMVCRESTClient.DoEncodeURL(var aURL: string);
begin
2020-09-08 03:21:28 +02:00
// It is necessary to encode the dots because the HTTPClient removes dotted URL segments.
// See https://tools.ietf.org/html/rfc3986#section-5.2.4
aURL := aURL.Replace('\', '/', [rfReplaceAll]);
aURL := aURL.Replace('../', '%2E%2E/', [rfReplaceAll]);
aURL := aURL.Replace('./', '%2E/', [rfReplaceAll]);
2020-09-08 03:21:28 +02:00
aURL := TURI.Create(aURL).Encode;
2020-08-14 00:43:25 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ExecuteRequest(const aMethod: TMVCHTTPMethodType): IMVCRESTResponse;
var
lURL: string;
begin
lURL := GetFullURL;
DoApplyPathParams(lURL);
DoApplyQueryParams(lURL);
DoEncodeURL(lURL);
DoApplyHeaders;
case aMethod of
httpGET: ;
httpPOST: ;
httpPUT: ;
httpDELETE: ;
httpHEAD: ;
httpOPTIONS: ;
httpPATCH: ;
httpTRACE: ;
end;
2020-08-09 02:18:36 +02:00
end;
function TMVCRESTClient.Get: IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.GetBodyFormData: TMultipartFormData;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
if not Assigned(fBodyFormData) then
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
fBodyFormData := TMultipartFormData.Create;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
Result := fBodyFormData;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.GetContentTypeCharset(const aContentType: string): string;
var
lContentType: string;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
SplitContentMediaTypeAndCharset(aContentType, lContentType, Result);
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.GetFullURL: string;
var
lResource: string;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := fBaseURL;
2020-08-09 02:18:36 +02:00
2020-09-08 03:21:28 +02:00
lResource := fResource;
if not lResource.IsEmpty then
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
if not Result.EndsWith('/') and
not (lResource.StartsWith('/') or lResource.StartsWith('?') or lResource.StartsWith('#')) then
begin
Result := Result + '/';
end;
2020-08-09 02:18:36 +02:00
2020-09-08 03:21:28 +02:00
Result := Result + lResource;
end;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Get(const aResource: string): IMVCRESTResponse;
2013-10-30 00:48:23 +01:00
begin
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.HandleRedirects(const aHandleRedirects: Boolean): IMVCRESTClient;
2015-12-18 20:59:40 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHTTPClient.HandleRedirects := aHandleRedirects;
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.HandleRedirects: Boolean;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.HandleRedirects;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.HeaderValue(const aName: string): string;
var
lHeader: TNetHeader;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := '';
for lHeader in fHeaders do
begin
if SameText(lHeader.Name, aName) then
Exit(lHeader.Value)
end;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.MaxRedirects(const aMaxRedirects: Integer): IMVCRESTClient;
2015-04-01 17:01:23 +02:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fHTTPClient.MaxRedirects := aMaxRedirects;
2015-04-01 17:01:23 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.MaxRedirects: Integer;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.MaxRedirects;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
class function TMVCRESTClient.New: IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := TMVCRESTClient.Create;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ObjectIsList(aObject: TObject): Boolean;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fRttiContext.GetType(aObject.ClassType).GetMethod('GetEnumerator') <> nil;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Patch(const aResource, aBody: string; const aDoNotEncode: Boolean;
const aContentType: string): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Patch: IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Patch(const aResource: string; aBody: TObject; const aOwnsBody: Boolean): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Post(const aResource, aBody: string; const aDoNotEncode: Boolean;
const aContentType: string): IMVCRESTResponse;
begin
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Post(const aResource: string; aBody: TObject; const aOwnsBody: Boolean): IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
begin
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Post: IMVCRESTResponse;
begin
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyPassword: string;
begin
2020-09-08 03:21:28 +02:00
Result := fProxySettings.Password;
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyPassword(const aProxyPassword: string): IMVCRESTClient;
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fProxySettings.Password := aProxyPassword;
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyPort: Integer;
begin
2020-09-08 03:21:28 +02:00
Result := fProxySettings.Port;
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyPort(const aProxyPort: Integer): IMVCRESTClient;
2020-08-26 22:13:18 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fProxySettings.Port := aProxyPort;
2020-08-26 22:13:18 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyServer(const aProxyServer: string): IMVCRESTClient;
2020-08-26 22:13:18 +02:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fProxySettings.Host := aProxyServer;
2020-08-26 22:13:18 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyServer: string;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := fProxySettings.Host;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyUsername(const aProxyUsername: string): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
Result := Self;
2020-09-08 03:21:28 +02:00
fProxySettings.UserName := aProxyUsername;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ProxyUsername: string;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fProxySettings.UserName;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Put: IMVCRESTResponse;
2013-10-30 00:48:23 +01:00
begin
2015-12-18 20:59:40 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Put(const aResource, aBody: string; const aDoNotEncode: Boolean;
const aContentType: string): IMVCRESTResponse;
2015-12-18 20:59:40 +01:00
begin
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Put(const aResource: string; aBody: TObject; const aOwnsBody: Boolean): IMVCRESTResponse;
begin
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ReadTimeout: Integer;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.ResponseTimeout;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.ReadTimeout(const aReadTimeout: Integer): IMVCRESTClient;
2015-04-01 17:01:23 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHTTPClient.ResponseTimeout := aReadTimeout;
2015-04-01 17:01:23 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.RegisterTypeSerializer(const aTypeInfo: PTypeInfo;
aInstance: IMVCTypeSerializer): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fSerializer.RegisterTypeSerializer(aTypeInfo, aInstance);
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Resource(const aResource: string): IMVCRESTClient;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fResource := aResource;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.Resource: string;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := fResource;
2020-08-09 02:18:36 +02:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.SecureProtocols: THTTPSecureProtocols;
2020-08-09 02:18:36 +02:00
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.SecureProtocols;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.SerializeObject(aObject: TObject): string;
begin
2020-09-08 03:21:28 +02:00
if ObjectIsList(aObject) then
Result := fSerializer.SerializeCollection(aObject)
else
Result := fSerializer.SerializeObject(aObject);
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.SecureProtocols(const aSecureProtocols: THTTPSecureProtocols): IMVCRESTClient;
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHTTPClient.SecureProtocols := aSecureProtocols;
2018-03-10 23:50:44 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.SetBasicAuthorization(const aUsername, aPassword: string): IMVCRESTClient;
2018-03-10 23:50:44 +01:00
begin
2020-08-09 02:18:36 +02:00
2018-03-10 23:50:44 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.SetBearerAuthorization(const aToken: string): IMVCRESTClient;
begin
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
procedure TMVCRESTClient.SetContentType(const aContentType: string);
2013-11-05 14:57:50 +01:00
begin
2020-09-08 03:21:28 +02:00
fHTTPClient.ContentType := aContentType;
2013-11-05 14:57:50 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.UserAgent(const aUserAgent: string): IMVCRESTClient;
2013-10-30 00:48:23 +01:00
begin
2020-09-08 03:21:28 +02:00
Result := Self;
fHTTPClient.UserAgent := aUserAgent;
2013-10-30 00:48:23 +01:00
end;
2020-09-08 03:21:28 +02:00
function TMVCRESTClient.UserAgent: string;
begin
2020-09-08 03:21:28 +02:00
Result := fHTTPClient.UserAgent;
end;
2013-10-30 00:48:23 +01:00
end.