From 81bb0bbe7bd2b26de0882655e8d41b2983f2620d Mon Sep 17 00:00:00 2001 From: viniciussanchez Date: Wed, 30 Oct 2019 17:48:50 -0300 Subject: [PATCH] Added a new overload of method body add --- src/core/RESTRequest4D.Request.Body.pas | 14 ++++++++++++++ src/interfaces/RESTRequest4D.Request.Body.Intf.pas | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/core/RESTRequest4D.Request.Body.pas b/src/core/RESTRequest4D.Request.Body.pas index 8c3869c..7ad7f1d 100644 --- a/src/core/RESTRequest4D.Request.Body.pas +++ b/src/core/RESTRequest4D.Request.Body.pas @@ -11,6 +11,7 @@ TRequestBody = class(TInterfacedObject, IRequestBody) function Clear: IRequestBody; function Add(const AContent: string; const AContentType: TRESTContentType = ctNone): IRequestBody; overload; function Add(const AContent: TJSONObject; const AOwns: Boolean = True): IRequestBody; overload; + function Add(const AContent: TJSONArray; const AOwns: Boolean = True): IRequestBody; overload; function Add(const AContent: TObject; const AOwns: Boolean = True): IRequestBody; overload; public constructor Create(const ARESTRequest: TRESTRequest); @@ -60,6 +61,19 @@ function TRequestBody.Add(const AContent: TObject; const AOwns: Boolean): IReque end; end; +function TRequestBody.Add(const AContent: TJSONArray; const AOwns: Boolean): IRequestBody; +begin + Result := Self; + if FRESTRequest.Method = TRESTRequestMethod.rmGET then + raise Exception.Create(NO_CONTENT_SHOULD_BE_ADDED); + if Assigned(AContent) then + begin + Self.Add(AContent.ToString, ctAPPLICATION_JSON); + if AOwns then + AContent.Free; + end; +end; + function TRequestBody.Clear: IRequestBody; begin Result := Self; diff --git a/src/interfaces/RESTRequest4D.Request.Body.Intf.pas b/src/interfaces/RESTRequest4D.Request.Body.Intf.pas index bc6f803..54f7c09 100644 --- a/src/interfaces/RESTRequest4D.Request.Body.Intf.pas +++ b/src/interfaces/RESTRequest4D.Request.Body.Intf.pas @@ -44,6 +44,19 @@ interface /// Adds content to the body of the request. /// /// + /// Content to be added in JSON array format. + /// + /// + /// Indicates who owns JSON. + /// + /// + /// Returns the instance itself following the fluent API pattern. + /// + function Add(const AContent: TJSONArray; const AOwns: Boolean = True): IRequestBody; overload; + /// + /// Adds content to the body of the request. + /// + /// /// Object that must be serialized. /// ///