2024-04-23 14:34:40 +02:00
// ***************************************************************************
2020-08-18 23:19:17 +02:00
//
// Delphi MVC Framework
//
2024-01-02 17:04:27 +01:00
// Copyright (c) 2010-2024 Daniele Teti and the DMVCFramework Team
2020-08-18 23:19:17 +02:00
//
// https://github.com/danieleteti/delphimvcframework
//
// Collaborators on this file:
2024-01-02 17:04:27 +01:00
// Jo<4A> o Ant<6E> nio Duarte (https://github.com/joaoduarte19)
2020-08-18 23:19:17 +02:00
//
// ***************************************************************************
//
// 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.
//
// *************************************************************************** }
2020-08-04 00:48:35 +02:00
unit MVCFramework. RESTClient. Intf;
2020-08-18 23:19:17 +02:00
{$I dmvcframework.inc}
2020-08-04 00:48:35 +02:00
interface
uses
2020-08-09 02:18:36 +02:00
System. SysUtils,
2020-09-08 03:21:28 +02:00
System. Classes,
System. TypInfo,
System. Net. HttpClient,
2020-09-24 21:29:49 +02:00
System. Net. URLClient,
2020-08-09 02:18:36 +02:00
MVCFramework. Serializer. Intf,
2020-08-27 19:32:09 +02:00
MVCFramework. Commons,
2020-09-08 03:21:28 +02:00
MVCFramework. Serializer. Commons,
2022-07-15 15:00:35 +02:00
Data. DB,
JsonDataObjects;
2020-08-04 00:48:35 +02:00
type
2020-12-17 00:05:39 +01:00
IMVCRESTResponse = interface ;
2022-07-15 15:00:35 +02:00
TNeedClientCertificateProc = reference to procedure( const aSender: TObject; const aRequest: TURLRequest;
const aCertificateList: TCertificateList; var aIndex: Integer ) ;
2020-09-24 21:29:49 +02:00
TValidateServerCertificateProc = reference to procedure( const aSender: TObject; const aRequest: TURLRequest;
2022-07-15 15:00:35 +02:00
const aCertificate: TCertificate; var aAccepted: Boolean ) ;
2020-12-17 00:05:39 +01:00
TBeforeRequestProc = reference to procedure ( aRequest: IHTTPRequest) ;
TRequestCompletedProc = reference to procedure ( aResponse: IHTTPResponse; var aHandled: Boolean ) ;
TResponseCompletedProc = reference to procedure( aResponse: IMVCRESTResponse) ;
2024-04-23 14:34:40 +02:00
TSendDataProc = reference to procedure( AContentLength, AWriteCount: Int64 ; var AAbort: Boolean ) ;
2020-08-09 02:18:36 +02:00
2020-08-18 23:19:17 +02:00
IMVCRESTClient = interface
2020-08-04 00:48:35 +02:00
[ '{592BC90F-B825-4B3B-84A7-6CA3927BAD69}' ]
2020-08-21 16:22:23 +02:00
function BaseURL( const aBaseURL: string ) : IMVCRESTClient; overload ;
2020-08-26 01:07:21 +02:00
function BaseURL( const aHost: string ; const aPort: Integer ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function BaseURL: string ; overload ;
2020-08-21 02:45:51 +02:00
2020-08-18 23:19:17 +02:00
function ProxyServer( const aProxyServer: string ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function ProxyServer: string ; overload ;
2020-08-18 23:19:17 +02:00
function ProxyPort( const aProxyPort: Integer ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function ProxyPort: Integer ; overload ;
2020-08-18 23:19:17 +02:00
function ProxyUsername( const aProxyUsername: string ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function ProxyUsername: string ; overload ;
2020-08-18 23:19:17 +02:00
function ProxyPassword( const aProxyPassword: string ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function ProxyPassword: string ; overload ;
2022-11-23 16:37:41 +01:00
function ProxyScheme( const aProxyScheme: string ) : IMVCRESTClient; overload ;
function ProxyScheme: string ; overload ;
2020-08-18 23:19:17 +02:00
2020-08-28 23:21:27 +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-08-28 23:21:27 +02:00
{$ENDIF}
2020-09-24 21:29:49 +02:00
2022-07-15 15:00:35 +02:00
/// <summary>
/// Method called when a ClientCertificate is needed.
/// </summary>
function SetNeedClientCertificateProc( aNeedClientCertificateProc: TNeedClientCertificateProc) : IMVCRESTClient;
2020-09-24 21:29:49 +02:00
/// <summary>
2020-12-17 00:05:39 +01:00
/// Add a custom SSL certificate validation. By default all certificates are accepted.
2020-09-24 21:29:49 +02:00
/// </summary>
function SetValidateServerCertificateProc( aValidateCertificateProc: TValidateServerCertificateProc) : IMVCRESTClient;
2020-08-20 20:08:41 +02:00
2020-12-17 00:05:39 +01:00
/// <summary>
/// Executes before send the request
/// </summary>
function SetBeforeRequestProc( aBeforeRequestProc: TBeforeRequestProc) : IMVCRESTClient;
/// <summary>
/// Executes after send the request
/// </summary>
function SetRequestCompletedProc( aRequestCompletedProc: TRequestCompletedProc) : IMVCRESTClient;
/// <summary>
/// Executes after the response is processed.
/// </summary>
function SetResponseCompletedProc( aResponseCompletedProc: TResponseCompletedProc) : IMVCRESTClient;
2024-05-02 19:14:59 +02:00
{$IF Defined(SYDNEYORBETTER)}
2024-04-23 14:34:40 +02:00
/// <summary>
/// Executes while sending data
/// </summary>
function SetSendDataProc( aSendDataProc: TSendDataProc) : IMVCRESTClient;
2024-05-02 19:14:59 +02:00
{$ENDIF}
2024-04-23 14:34:40 +02:00
2022-07-15 15:00:35 +02:00
///<summary>
/// Set the client certificate for the request</summary>
/// </summary>
function SetClientCertificate( const aCertStream: TStream; const aPassword: string ) : IMVCRESTClient; overload ;
2022-07-15 20:42:29 +02:00
{$IF defined(TOKYOORBETTER)}
2022-07-15 15:00:35 +02:00
/// <summary>
/// Set the path containing a client certificate for the request (iOS, Linux, Windows, Android).
/// Note, on Android the Path is certificate fingerprint or imported name, not a file path.
/// Password is not used.
/// </summary>
function SetClientCertificate( const aCertPath, aPassword: string ) : IMVCRESTClient; overload ;
2022-07-15 20:42:29 +02:00
{$ENDIF}
2022-07-15 15:00:35 +02:00
2020-08-21 02:45:51 +02:00
/// <summary>
2020-09-11 19:55:26 +02:00
/// Clears all parameters (headers, body, path params and query params). This method is executed after each
/// request is completed.
2020-08-21 02:45:51 +02:00
/// </summary>
2020-08-20 20:08:41 +02:00
function ClearAllParams: IMVCRESTClient;
2022-07-15 20:42:29 +02:00
{$IF defined(BERLINORBETTER)}
2020-08-20 20:08:41 +02:00
/// <summary>
2020-08-21 16:22:23 +02:00
/// Connection timeout in milliseconds to be used for the requests.
2020-08-20 20:08:41 +02:00
/// </summary>
2020-08-21 16:22:23 +02:00
function ConnectTimeout( const aConnectTimeout: Integer ) : IMVCRESTClient; overload ;
function ConnectTimeout: Integer ; overload ;
2020-08-20 20:08:41 +02:00
/// <summary>
2020-08-21 16:22:23 +02:00
/// Response reading timeout in milliseconds to be used for the requests.
2020-08-20 20:08:41 +02:00
/// </summary>
2020-08-21 16:22:23 +02:00
function ReadTimeout( const aReadTimeout: Integer ) : IMVCRESTClient; overload ;
function ReadTimeout: Integer ; overload ;
2022-07-15 20:42:29 +02:00
{$ENDIF}
2020-08-20 20:08:41 +02:00
2020-08-18 23:19:17 +02:00
/// <summary>
2020-08-21 16:22:23 +02:00
/// Add basic authorization header. Authorization = Basic <Username:Password> (encoded in Base64)
2020-08-18 23:19:17 +02:00
/// </summary>
2020-09-24 20:03:11 +02:00
function SetBasicAuthorization( const aUsername, aPassword: string ) : IMVCRESTClient;
2020-08-18 23:19:17 +02:00
/// <summary>
2020-08-21 16:22:23 +02:00
/// Add bearer authorization header. Authorization = Bearer <Token>
2020-08-18 23:19:17 +02:00
/// </summary>
2020-09-24 20:03:11 +02:00
function SetBearerAuthorization( const aAccessToken: string ) : IMVCRESTClient;
/// <summary>
/// Returns the stored authorization. Includes Basic or Bearer prefix
/// </summary>
function Authorization: string ;
/// <summary>
/// Removes the authorization header defined in <see cref="MVCFramework.RESTClient.Intf|IMVCRESTClient.SetBasicAuthorization(string,string)">
/// SetBasicAuthorization</see> or <see cref="MVCFramework.RESTClient.Intf|IMVCRESTClient.SetBearerAuthorization(string)">
/// SetBearerAuthorization</see>
/// </summary>
function ClearAuthorization: IMVCRESTClient;
2020-08-18 23:19:17 +02:00
/// <summary>
2020-08-20 20:08:41 +02:00
/// Add a header.
2020-08-18 23:19:17 +02:00
/// </summary>
/// <param name="aName">
/// Header name
/// </param>
/// <param name="aValue">
/// Header value
/// </param>
2020-08-20 20:08:41 +02:00
/// <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 ;
2020-08-26 14:05:12 +02:00
function HeaderValue( const aName: string ) : string ;
2021-01-15 19:31:33 +01:00
function Headers: TNameValueArray;
2020-08-18 23:19:17 +02:00
/// <summary>
/// Clears all headers.
/// </summary>
function ClearHeaders: IMVCRESTClient;
2020-08-21 16:22:23 +02:00
function AllowCookies( const aAllowCookies: Boolean ) : IMVCRESTClient; overload ;
function AllowCookies: Boolean ; overload ;
2020-09-24 20:03:11 +02:00
/// <summary>
/// Add DMVC session cookie
/// </summary>
function SessionId( const aSessionId: string ) : IMVCRESTClient; overload ;
function SessionId: string ; overload ;
2020-08-18 23:19:17 +02:00
/// <summary>
/// Add a cookie header.
/// </summary>
function AddCookie( const aName, aValue: string ) : IMVCRESTClient;
/// <summary>
/// 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&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;
2020-08-04 00:48:35 +02:00
2020-08-18 23:19:17 +02:00
function Accept( const aAccept: string ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function Accept: string ; overload ;
2020-08-18 23:19:17 +02:00
function AcceptCharset( const aAcceptCharset: string ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function AcceptCharset: string ; overload ;
2020-08-18 23:19:17 +02:00
function AcceptEncoding( const aAcceptEncoding: string ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function AcceptEncoding: string ; overload ;
2020-09-08 03:21:28 +02:00
2020-08-20 20:08:41 +02:00
function HandleRedirects( const aHandleRedirects: Boolean ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function HandleRedirects: Boolean ; overload ;
2020-09-08 03:21:28 +02:00
function MaxRedirects( const aMaxRedirects: Integer ) : IMVCRESTClient; overload ;
function MaxRedirects: Integer ; overload ;
2020-08-04 00:48:35 +02:00
2020-09-24 21:29:49 +02:00
function UserAgent( const aUserAgent: string ) : IMVCRESTClient; overload ;
function UserAgent: string ; overload ;
2020-08-18 23:19:17 +02:00
function Resource( const aResource: string ) : IMVCRESTClient; overload ;
2020-08-21 16:22:23 +02:00
function Resource: string ; overload ;
2020-08-20 23:35:28 +02:00
2020-08-18 23:19:17 +02:00
/// <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 ;
2020-08-18 23:19:17 +02:00
/// <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 ;
2020-08-18 23:19:17 +02:00
/// <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 ;
/// <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-09-08 03:21:28 +02:00
function AddFile( const aName, aFileName: string ; const aContentType: string = '' ) : IMVCRESTClient; overload ;
function AddFile( const aFileName: string ; const aContentType: string = '' ) : IMVCRESTClient; overload ;
2023-04-25 15:27:55 +02:00
{$IF defined(RIOORBETTER)}
function AddFile( const aName: string ; aFileStreamValue: TStream; const aFileName: string = '' ;
const aContentType: string = '' ) : IMVCRESTClient; overload ;
{$ENDIF}
2020-09-08 03:21:28 +02:00
function AddBodyFieldFormData( const aName, aValue: string ) : IMVCRESTClient; overload ;
2020-09-23 01:26:13 +02:00
{$IF defined(RIOORBETTER)}
2020-09-08 03:21:28 +02:00
function AddBodyFieldFormData( const aName: string ; aStreamValue: TStream;
2020-08-27 19:32:09 +02:00
const aContentType: string = '' ) : IMVCRESTClient; overload ;
2020-09-23 01:26:13 +02:00
{$ENDIF}
2020-09-24 20:03:11 +02:00
/// <summary>
2020-09-11 19:55:26 +02:00
/// Add a field to the x-www-form-urlencoded body. You must set ContentType to application/x-www-form-urlencoded
2020-09-08 03:21:28 +02:00
/// </summary>
function AddBodyFieldURLEncoded( const aName, aValue: string ) : IMVCRESTClient;
function ClearBody: IMVCRESTClient;
2020-08-20 20:08:41 +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>
2020-08-21 02:45:51 +02:00
function Async( aCompletionHandler: TProc< IMVCRESTResponse> ; aCompletionHandlerWithError: TProc< Exception> = nil ;
2020-08-26 01:07:21 +02:00
const aSynchronized: Boolean = False ) : IMVCRESTClient;
2020-08-04 00:48:35 +02:00
2020-08-18 23:19:17 +02:00
/// <summary>
2021-08-13 17:06:15 +02:00
/// Execute a Get request. The GET method requests a representation of the specified resource.
/// Requests using GET should only retrieve data.
/// Sending body/payload in a GET request may cause some existing implementations to
2024-01-02 17:04:27 +01:00
/// reject the request <20> while not prohibited by the specification, the semantics
2021-08-13 17:06:15 +02:00
/// are undefined. It is better to just avoid sending payloads in GET requests.
2020-08-18 23:19:17 +02:00
/// </summary>
function Get( const aResource: string ) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Get request. The GET method requests a representation of the specified resource.
/// Requests using GET should only retrieve data.
/// Sending body/payload in a GET request may cause some existing implementations to
2024-01-02 17:04:27 +01:00
/// reject the request <20> while not prohibited by the specification, the semantics
2021-08-13 17:06:15 +02:00
/// are undefined. It is better to just avoid sending payloads in GET requests.
/// </summary>
2020-08-21 16:22:23 +02:00
function Get: IMVCRESTResponse; overload ;
2020-08-04 00:48:35 +02:00
2020-12-16 22:42:25 +01:00
/// <summary>
2021-08-13 17:06:15 +02:00
/// Execute a Head request. The HEAD method asks for a response identical
/// to that of a GET request, but without the response body.
2020-12-16 22:42:25 +01:00
/// </summary>
function Head( const aResource: string ) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Head request. The HEAD method asks for a response identical
/// to that of a GET request, but without the response body.
/// </summary>
2020-12-16 22:42:25 +01:00
function Head: IMVCRESTResponse; overload ;
/// <summary>
2021-08-13 17:06:15 +02:00
/// Execute a Options request. The OPTIONS method is used to describe the communication options for the target resource.
2020-12-16 22:42:25 +01:00
/// </summary>
function Options( const aResource: string ) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Options request. The OPTIONS method is used to describe the communication options for the target resource.
/// </summary>
2020-12-16 22:42:25 +01:00
function Options: IMVCRESTResponse; overload ;
2020-08-18 23:19:17 +02:00
/// <summary>
2021-08-13 17:06:15 +02:00
/// Execute a Post request. The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.
2020-08-18 23:19:17 +02:00
/// </summary>
2020-08-26 14:05:12 +02:00
/// <param name="aResource">
2020-09-11 19:55:26 +02:00
/// Resource path
2020-08-26 14:05:12 +02:00
/// </param>
/// <param name="aBody">
2020-09-11 19:55:26 +02:00
/// Object to be serialized. It can be a simple object or a list of objects (TObjectList <T>)
2020-08-26 14:05:12 +02:00
/// </param>
/// <param name="aOwnsBody">
2020-09-11 19:55:26 +02:00
/// If OwnsBody is true, Body will be destroyed by IMVCRESTClient. <br />
2020-08-26 14:05:12 +02:00
/// </param>
2020-08-18 23:19:17 +02:00
function Post( const aResource: string ; aBody: TObject; const aOwnsBody: Boolean = True ) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Post request. The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.
/// </summary>
/// <param name="aResource">
/// Resource path
/// </param>
/// <param name="aBody">
/// Serialized data sent as body request. It can be a simple object or a list of objects (TObjectList <T>)
/// </param>
/// <param name="aContentType">
/// Format of the body data. Must be one of the allowed media-types <br />
/// </param>
2020-09-10 02:40:14 +02:00
function Post( const aResource: string ; const aBody: string = '' ;
2020-08-27 19:32:09 +02:00
const aContentType: string = TMVCMediaType. APPLICATION_JSON) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Post request. The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.
/// </summary>
2020-08-21 16:22:23 +02:00
function Post: IMVCRESTResponse; overload ;
2020-08-04 00:48:35 +02:00
2020-08-18 23:19:17 +02:00
/// <summary>
2021-08-13 17:06:15 +02:00
/// Execute a Patch request. The PATCH method is used to apply partial modifications to a resource.
2020-08-18 23:19:17 +02:00
/// </summary>
2020-08-21 16:22:23 +02:00
function Patch( const aResource: string ; aBody: TObject;
const aOwnsBody: Boolean = True ) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Patch request. The PATCH method is used to apply partial modifications to a resource.
/// </summary>
2020-09-10 02:40:14 +02:00
function Patch( const aResource: string ; const aBody: string = '' ;
2020-08-27 19:32:09 +02:00
const aContentType: string = TMVCMediaType. APPLICATION_JSON) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Patch request. The PATCH method is used to apply partial modifications to a resource.
/// </summary>
2020-08-21 16:22:23 +02:00
function Patch: IMVCRESTResponse; overload ;
2020-08-04 00:48:35 +02:00
2020-08-18 23:19:17 +02:00
/// <summary>
2021-08-13 17:06:15 +02:00
/// Execute a Put request. The PUT method replaces all current representations of the target resource with the request payload.
2020-08-18 23:19:17 +02:00
/// </summary>
function Put( const aResource: string ; aBody: TObject; const aOwnsBody: Boolean = True ) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Put request. The PUT method replaces all current representations of the target resource with the request payload.
/// </summary>
2020-09-10 02:40:14 +02:00
function Put( const aResource: string ; const aBody: string = '' ;
2020-08-27 19:32:09 +02:00
const aContentType: string = TMVCMediaType. APPLICATION_JSON) : IMVCRESTResponse; overload ;
2021-08-13 17:06:15 +02:00
/// <summary>
/// Execute a Put request. The PUT method replaces all current representations of the target resource with the request payload.
/// </summary>
2020-08-21 16:22:23 +02:00
function Put: IMVCRESTResponse; overload ;
2020-08-09 02:18:36 +02:00
2020-08-18 23:19:17 +02:00
/// <summary>
2021-08-13 17:06:15 +02:00
/// Execute a Delete request. The DELETE method deletes the specified resource.
2020-08-18 23:19:17 +02:00
/// </summary>
function Delete( const aResource: string ) : IMVCRESTResponse; overload ;
2020-08-21 16:22:23 +02:00
function Delete: IMVCRESTResponse; overload ;
2020-08-09 02:18:36 +02:00
2020-09-29 16:56:25 +02:00
/// <summary>
/// Executes any type of HTTP request
/// </summary>
function Execute( const aMethod: TMVCHTTPMethodType; const aResource: string ) : IMVCRESTResponse; overload ;
function Execute( const aMethod: TMVCHTTPMethodType) : IMVCRESTResponse; overload ;
2020-08-18 23:19:17 +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 = [ ] ;
2020-08-18 23:19:17 +02:00
const aNameCase: TMVCNameCase = ncAsIs) : IMVCRESTResponse;
/// <summary>
/// Serialize the current dataset record and execute a PUT request.
/// </summary>
2020-08-26 14:05:12 +02:00
function DataSetUpdate( const aResource, aKeyValue: string ; aDataSet: TDataSet;
const aIgnoredFields: TMVCIgnoredList = [ ] ; const aNameCase: TMVCNameCase = ncAsIs) : IMVCRESTResponse;
2020-08-18 23:19:17 +02:00
/// <summary>
/// Delete the current dataset record by executing a delete request.
/// </summary>
2020-08-26 14:05:12 +02:00
function DataSetDelete( const aResource, aKeyValue: string ) : IMVCRESTResponse;
2020-08-09 02:18:36 +02:00
2021-04-11 22:37:14 +02:00
/// <summary>
/// Access the RESTClient serializer
/// </summary>
function Serializer: IMVCSerializer; overload ;
/// <summary>
/// Add a serializer to the RESTClient
/// </summary>
function Serializer( const aSerializer: IMVCSerializer) : IMVCRESTClient; overload ;
2020-08-18 23:19:17 +02:00
/// <summary>
/// Register a custom serializer to the RESTClient serializer.
/// </summary>
function RegisterTypeSerializer( const aTypeInfo: PTypeInfo; aInstance: IMVCTypeSerializer) : IMVCRESTClient;
2020-08-09 02:18:36 +02:00
end ;
2020-08-18 23:19:17 +02:00
IMVCRESTResponse = interface
2020-08-09 02:18:36 +02:00
[ '{BF611B46-CCD1-47C7-8D8B-82EA0518896B}' ]
2020-08-04 00:48:35 +02:00
2020-09-24 20:03:11 +02:00
/// <summary>
/// Success if StatusCode is >= 200 and < 300
/// </summary>
2020-08-09 02:18:36 +02:00
function Success: Boolean ;
function StatusCode: Integer ;
function StatusText: string ;
function Headers: TStrings;
2020-08-26 01:07:21 +02:00
function HeaderValue( const aName: string ) : string ;
2020-08-21 02:45:51 +02:00
function Cookies: TCookies;
2023-05-23 11:45:58 +02:00
function CookieByName( const aName: string ; const RaiseExceptionIfNotFound: Boolean = False ) : TCookie;
2020-08-09 02:18:36 +02:00
function Server: string ;
function ContentType: string ;
function ContentEncoding: string ;
function ContentLength: Integer ;
function Content: string ;
2020-09-24 20:03:11 +02:00
function ContentRawBytes: TBytes;
2020-08-09 02:18:36 +02:00
procedure SaveContentToStream( aStream: TStream) ;
procedure SaveContentToFile( const aFileName: string ) ;
2021-10-20 11:29:49 +02:00
function ToJSONObject: TJDOJsonObject;
function ToJSONArray: TJDOJsonArray;
2022-08-03 19:28:01 +02:00
procedure BodyFor( const aObject: TObject; const aRootNode: string = '' ) ;
procedure BodyForListOf( const aObjectList: TObject; const aObjectClass: TClass; const aRootNode: string = '' ) ;
2020-08-04 00:48:35 +02:00
end ;
implementation
end .