Skip to content

Commit

Permalink
Added parameter contenttype to RESTClient engine
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Jan 20, 2021
1 parent 20e78b3 commit d0bb5d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/RESTRequest4D.Request.Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ TRequestClient = class(TInterfacedObject, IRequest)
function Delete: IResponse;
function Patch: IResponse;
function ClearBody: IRequest;
function AddBody(const AContent: string): IRequest; overload;
function AddParam(const AName, AValue: string; const AKind: TRESTRequestParameterKind = {$IF COMPILERVERSION < 33}TRESTRequestParameterKind.pkGETorPOST{$ELSE}TRESTRequestParameterKind.pkQUERY{$ENDIF}): IRequest;
function AddBody(const AContent: string; const AContentType: TRESTContentType = ctAPPLICATION_JSON): IRequest; overload;
function AddBody(const AContent: TJSONObject; const AOwns: Boolean = True): IRequest; overload;
function AddBody(const AContent: TJSONArray; const AOwns: Boolean = True): IRequest; overload;
function AddBody(const AContent: TObject; const AOwns: Boolean = True): IRequest; overload;
Expand All @@ -56,7 +57,6 @@ TRequestClient = class(TInterfacedObject, IRequest)
function ContentType(const AContentType: string): IRequest;
function UserAgent(const AName: string): IRequest;
function AddCookies(const ACookies: TStrings): IRequest;
function AddParam(const AName, AValue: string): IRequest;
function AddFile(const AName: string; const AValue: TStream): IRequest;
public
constructor Create;
Expand All @@ -68,15 +68,15 @@ implementation
uses DataSet.Serialize, System.Generics.Collections, FireDAC.Comp.DataSet, FireDAC.Comp.Client, RESTRequest4D.Response.Client,
RESTRequest4D.Utils;

function TRequestClient.AddBody(const AContent: string): IRequest;
function TRequestClient.AddBody(const AContent: string; const AContentType: TRESTContentType): IRequest;
begin
Result := Self;
if AContent.Trim.IsEmpty then
Exit;
{$IF COMPILERVERSION <= 29}
FRESTRequest.AddBody(AContent);
FRESTRequest.AddBody(AContent, AContentType);
{$ELSE}
FRESTRequest.Body.Add(AContent);
FRESTRequest.Body.Add(AContent, AContentType);
{$ENDIF}
end;

Expand Down Expand Up @@ -145,13 +145,13 @@ function TRequestClient.AddHeader(const AName, AValue: string): IRequest;
FRESTRequest.Params.AddHeader(AName, AValue);
end;

function TRequestClient.AddParam(const AName, AValue: string): IRequest;
function TRequestClient.AddParam(const AName, AValue: string; const AKind: TRESTRequestParameterKind): IRequest;
begin
Result := Self;
if AName.Trim.IsEmpty or AValue.Trim.IsEmpty then
Exit;
FParams.Add(AName);
FRESTRequest.AddParameter(AName, AValue, {$IF COMPILERVERSION < 33}TRESTRequestParameterKind.pkGETorPOST{$ELSE}TRESTRequestParameterKind.pkQUERY{$ENDIF});
FRESTRequest.AddParameter(AName, AValue, AKind);
end;

function TRequestClient.BasicAuthentication(const AUsername, APassword: string): IRequest;
Expand Down
10 changes: 9 additions & 1 deletion src/RESTRequest4D.Request.Contract.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
interface

uses RESTRequest4D.Response.Contract,
{$IF NOT (DEFINED(RR4D_INDY) or DEFINED(FPC) or DEFINED(RR4D_NETHTTP))}
REST.Types,
{$ENDIF}
{$IFDEF FPC}
SysUtils, fpjson, Classes, DB;
{$ELSE}
Expand Down Expand Up @@ -39,7 +42,13 @@ interface
function Patch: IResponse;
function FullRequestURL(const AIncludeParams: Boolean = True): string;
function ClearBody: IRequest;
{$IF DEFINED(RR4D_INDY) or DEFINED(FPC) or DEFINED(RR4D_NETHTTP)}
function AddParam(const AName, AValue: string): IRequest;
function AddBody(const AContent: string): IRequest; overload;
{$ELSE}
function AddParam(const AName, AValue: string; const AKind: TRESTRequestParameterKind = {$IF COMPILERVERSION < 33}TRESTRequestParameterKind.pkGETorPOST{$ELSE}TRESTRequestParameterKind.pkQUERY{$ENDIF}): IRequest;
function AddBody(const AContent: string; const AContentType: TRESTContentType = ctAPPLICATION_JSON): IRequest; overload;
{$ENDIF}
function AddBody(const AContent: TJSONObject; const AOwns: Boolean = True): IRequest; overload;
function AddBody(const AContent: TJSONArray; const AOwns: Boolean = True): IRequest; overload;
function AddBody(const AContent: TObject; const AOwns: Boolean = True): IRequest; overload;
Expand All @@ -50,7 +59,6 @@ interface
function UserAgent(const AName: string): IRequest;
function ContentType(const AContentType: string): IRequest;
function AddCookies(const ACookies: TStrings): IRequest;
function AddParam(const AName, AValue: string): IRequest;
function AddFile(const AName: string; const AValue: TStream): IRequest;
end;

Expand Down

0 comments on commit d0bb5d4

Please sign in to comment.