Skip to content

Commit 4a08873

Browse files
exposed Send method on client to simplify sending
removed generic methods for now since serialization not implemented.
1 parent 12b9818 commit 4a08873

5 files changed

Lines changed: 154 additions & 909 deletions

File tree

Source/VSoft.HttpClient.WinHttpClient.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ THttpClient = class(THttpClientBase, IHttpClient, IHttpClientInternal)
106106

107107

108108
//IHttpClientInternal
109-
function Send(const request : TRequest; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
109+
function Send(const request : TRequest; const cancellationToken : ICancellationToken = nil) : IHttpResponse;
110110

111111

112112
public
@@ -832,6 +832,7 @@ function THttpClient.Send(const request: TRequest; const cancellationToken: ICan
832832
end;
833833

834834

835+
835836
procedure THttpClient.SetAllowSelfSignedCertificates(const value: boolean);
836837
begin
837838
FAllowSelfSignedCertificates := value;

Source/VSoft.HttpClient.pas

Lines changed: 146 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ interface
1010
VSoft.Uri;
1111

1212

13+
{$IFDEF CONDITIONALEXPRESSIONS} //Started being defined with D2009
14+
{$IF CompilerVersion < 23.0} // Before RAD Studio XE2
15+
{$DEFINE UNSUPPORTED_COMPILER_VERSION}
16+
{$IFEND}
17+
{$IF CompilerVersion > 24.0 } //XE4 or later
18+
{$LEGACYIFEND ON}
19+
{$IFEND}
20+
{$ELSE}
21+
{$DEFINE UNSUPPORTED_COMPILER_VERSION}
22+
{$ENDIF}
23+
24+
25+
1326
type
1427
THttpAuthType = (None, Basic);
1528
THttpMethod = (GET,POST, PUT, PATCH, DELETE);
@@ -176,24 +189,25 @@ TRequest = class
176189

177190
function ForceFormData(const value : boolean = true) : TRequest;
178191

192+
//Note - ideally these methods would be on the client - but non gerneric interfaces cannot have generic methods.
179193
//execute
180194
function Get(const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
181-
function Get<T : class>(const cancellationToken : ICancellationToken = nil) : T;overload;
195+
// function Get<T : class>(const cancellationToken : ICancellationToken = nil) : T;overload;
182196

183197
function Post(const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
184-
function Post<T : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
185-
function Post<T : class; R : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : R;overload;
198+
// function Post<T : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
199+
// function Post<T : class; R : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : R;overload;
186200

187201
function Patch(const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
188-
function Patch<T : class>(const entity : T ; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
189-
function Patch<T : class; R : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : R;overload;
202+
// function Patch<T : class>(const entity : T ; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
203+
// function Patch<T : class; R : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : R;overload;
190204

191205
function Put(const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
192-
function Put<T : class>(const entity : T ; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
193-
function Put<T : class; R : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : R;overload;
206+
// function Put<T : class>(const entity : T ; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
207+
// function Put<T : class; R : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : R;overload;
194208

195209
function Delete(const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
196-
function Delete<T : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
210+
// function Delete<T : class>(const entity : T; const cancellationToken : ICancellationToken = nil) : IHttpResponse;overload;
197211

198212
property Headers : TStrings read GetHeaders;
199213
property Parameters : TStrings read GetParameters;
@@ -206,7 +220,7 @@ TRequest = class
206220
property ContentType : string read GetContentType write SetContentType;
207221

208222
property FollowRedirects : boolean read FFollowRedirects write FFollowRedirects;
209-
property HtttpMethod : THttpMethod read FHttpMethod;
223+
property HtttpMethod : THttpMethod read FHttpMethod write FHttpMethod;
210224
property Resource : string read GetResource write SetResource;
211225
property ContentLength : Int64 read GetContentLength;
212226
property SaveAsFile : string read FSaveAsFile write FSaveAsFile;
@@ -268,6 +282,8 @@ TRequest = class
268282
procedure UseSerializer(const useFunc : TUseSerializerFunc);overload;
269283
procedure UseSerializer(const serializer : IRestSerializer);overload;
270284

285+
function Send(const request : TRequest; const cancellationToken : ICancellationToken = nil) : IHttpResponse;
286+
271287
property AllowSelfSignedCertificates : boolean read GetAllowSelfSignedCertificates write SetAllowSelfSignedCertificates;
272288
property AuthType : THttpAuthType read GetAuthType write SetAuthType;
273289
property BaseUri : string read GetBaseUri write SetBaseUri;
@@ -500,18 +516,18 @@ function TRequest.Delete(const cancellationToken: ICancellationToken): IHttpResp
500516
result := lClient.Send(self, cancellationToken);
501517
end;
502518

503-
function TRequest.Delete<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
504-
var
505-
entityType : PTypeInfo;
506-
lClient : IHttpClientInternal;
507-
begin
508-
raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
509-
FHttpMethod := THttpMethod.DELETE;
510-
entityType := TypeInfo(T);
511-
//TODO : Serialize entity
512-
lClient := GetClient;
513-
result := lClient.Send(self,cancellationToken);
514-
end;
519+
//function TRequest.Delete<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
520+
//var
521+
// entityType : PTypeInfo;
522+
// lClient : IHttpClientInternal;
523+
//begin
524+
// raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
525+
// FHttpMethod := THttpMethod.DELETE;
526+
// entityType := TypeInfo(T);
527+
// //TODO : Serialize entity
528+
// lClient := GetClient;
529+
// result := lClient.Send(self,cancellationToken);
530+
//end;
515531

516532
destructor TRequest.Destroy;
517533
begin
@@ -542,21 +558,21 @@ function TRequest.Get(const cancellationToken: ICancellationToken): IHttpRespons
542558
result := lClient.Send(Self, cancellationToken);
543559
end;
544560

545-
function TRequest.Get<T>(const cancellationToken: ICancellationToken): T;
546-
var
547-
returnType : PTypeInfo;
548-
response : IHttpResponse;
549-
lClient : IHttpClientInternal;
550-
begin
551-
raise ENotImplemented.Create('Deserialization not implemented yet');
552-
553-
FHttpMethod := THttpMethod.GET;
554-
returnType := TypeInfo(T);
555-
lClient := GetClient;
556-
response := lClient.Send(self, cancellationToken);
557-
//TODO : deserialized the response
558-
result := nil
559-
end;
561+
//function TRequest.Get<T>(const cancellationToken: ICancellationToken): T;
562+
//var
563+
// returnType : PTypeInfo;
564+
// response : IHttpResponse;
565+
// lClient : IHttpClientInternal;
566+
//begin
567+
// raise ENotImplemented.Create('Deserialization not implemented yet');
568+
//
569+
// FHttpMethod := THttpMethod.GET;
570+
// returnType := TypeInfo(T);
571+
// lClient := GetClient;
572+
// response := lClient.Send(self, cancellationToken);
573+
// //TODO : deserialized the response
574+
// result := nil
575+
//end;
560576

561577
function TRequest.GetAccept: string;
562578
begin
@@ -694,38 +710,38 @@ function TRequest.Patch(const cancellationToken: ICancellationToken): IHttpRespo
694710
result := lClient.Send(self, cancellationToken);
695711
end;
696712

697-
function TRequest.Patch<T, R>(const entity : T; const cancellationToken: ICancellationToken): R;
698-
var
699-
entityType : PTypeInfo;
700-
returnType : PTypeInfo;
701-
response : IHttpResponse;
702-
lClient : IHttpClientInternal;
703-
begin
704-
raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
705-
FHttpMethod := THttpMethod.PATCH;
706-
entityType := TypeInfo(T);
707-
returnType := TypeInfo(R);
708-
lClient := GetClient;
709-
response := lClient.Send(Self, cancellationToken);
710-
711-
result := nil;
712-
end;
713-
714-
function TRequest.Patch<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
715-
var
716-
entityType : PTypeInfo;
717-
response : IHttpResponse;
718-
lClient : IHttpClientInternal;
719-
begin
720-
raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
721-
722-
FHttpMethod := THttpMethod.PATCH;
723-
entityType := TypeInfo(T);
724-
lClient := GetClient;
725-
response := lClient.Send(self, cancellationToken);
726-
727-
result := nil;
728-
end;
713+
//function TRequest.Patch<T, R>(const entity : T; const cancellationToken: ICancellationToken): R;
714+
//var
715+
// entityType : PTypeInfo;
716+
// returnType : PTypeInfo;
717+
// response : IHttpResponse;
718+
// lClient : IHttpClientInternal;
719+
//begin
720+
// raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
721+
// FHttpMethod := THttpMethod.PATCH;
722+
// entityType := TypeInfo(T);
723+
// returnType := TypeInfo(R);
724+
// lClient := GetClient;
725+
// response := lClient.Send(Self, cancellationToken);
726+
//
727+
// result := nil;
728+
//end;
729+
730+
//function TRequest.Patch<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
731+
//var
732+
// entityType : PTypeInfo;
733+
// response : IHttpResponse;
734+
// lClient : IHttpClientInternal;
735+
//begin
736+
// raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
737+
//
738+
// FHttpMethod := THttpMethod.PATCH;
739+
// entityType := TypeInfo(T);
740+
// lClient := GetClient;
741+
// response := lClient.Send(self, cancellationToken);
742+
//
743+
// result := nil;
744+
//end;
729745

730746
function TRequest.Post(const cancellationToken: ICancellationToken): IHttpResponse;
731747
var
@@ -736,37 +752,37 @@ function TRequest.Post(const cancellationToken: ICancellationToken): IHttpRespon
736752
result := lClient.Send(self, cancellationToken);
737753
end;
738754

739-
function TRequest.Post<T, R>(const entity : T; const cancellationToken: ICancellationToken): R;
740-
var
741-
entityType : PTypeInfo;
742-
returnType : PTypeInfo;
743-
response : IHttpResponse;
744-
lClient : IHttpClientInternal;
745-
begin
746-
raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
747-
748-
FHttpMethod := THttpMethod.POST;
749-
entityType := TypeInfo(T);
750-
returnType := TypeInfo(R);
751-
lClient := GetClient;
752-
response := lClient.Send(Self, cancellationToken );
753-
result := nil;
754-
end;
755-
756-
function TRequest.Post<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
757-
var
758-
entityType : PTypeInfo;
759-
lClient : IHttpClientInternal;
760-
begin
761-
raise ENotImplemented.Create('Serialization not implemented yet');
762-
763-
FHttpMethod := THttpMethod.POST;
764-
entityType := TypeInfo(T);
765-
766-
//TODO : serialize entity
767-
lClient := GetClient;
768-
result := lClient.Send(self, cancellationToken);
769-
end;
755+
//function TRequest.Post<T, R>(const entity : T; const cancellationToken: ICancellationToken): R;
756+
//var
757+
// entityType : PTypeInfo;
758+
// returnType : PTypeInfo;
759+
// response : IHttpResponse;
760+
// lClient : IHttpClientInternal;
761+
//begin
762+
// raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
763+
//
764+
// FHttpMethod := THttpMethod.POST;
765+
// entityType := TypeInfo(T);
766+
// returnType := TypeInfo(R);
767+
// lClient := GetClient;
768+
// response := lClient.Send(Self, cancellationToken );
769+
// result := nil;
770+
//end;
771+
772+
//function TRequest.Post<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
773+
//var
774+
// entityType : PTypeInfo;
775+
// lClient : IHttpClientInternal;
776+
//begin
777+
// raise ENotImplemented.Create('Serialization not implemented yet');
778+
//
779+
// FHttpMethod := THttpMethod.POST;
780+
// entityType := TypeInfo(T);
781+
//
782+
// //TODO : serialize entity
783+
// lClient := GetClient;
784+
// result := lClient.Send(self, cancellationToken);
785+
//end;
770786

771787
function TRequest.Put(const cancellationToken: ICancellationToken): IHttpResponse;
772788
var
@@ -777,37 +793,37 @@ function TRequest.Put(const cancellationToken: ICancellationToken): IHttpRespons
777793
result := lClient.Send(self, cancellationToken);
778794
end;
779795

780-
function TRequest.Put<T, R>(const entity: T; const cancellationToken: ICancellationToken): R;
781-
var
782-
entityType : PTypeInfo;
783-
returnType : PTypeInfo;
784-
response : IHttpResponse;
785-
lClient : IHttpClientInternal;
786-
begin
787-
raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
788-
FHttpMethod := THttpMethod.PUT;
789-
entityType := TypeInfo(T);
790-
returnType := TypeInfo(R);
791-
lClient := GetClient;
792-
response := lClient.Send(Self, cancellationToken );
793-
794-
result := nil;
795-
796-
end;
797-
798-
function TRequest.Put<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
799-
var
800-
entityType : PTypeInfo;
801-
lClient : IHttpClientInternal;
802-
begin
803-
raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
804-
FHttpMethod := THttpMethod.PUT;
805-
entityType := TypeInfo(T);
806-
807-
//TODO : Serialize!
808-
lClient := GetClient;
809-
result := lClient.Send(self, cancellationToken);
810-
end;
796+
//function TRequest.Put<T, R>(const entity: T; const cancellationToken: ICancellationToken): R;
797+
//var
798+
// entityType : PTypeInfo;
799+
// returnType : PTypeInfo;
800+
// response : IHttpResponse;
801+
// lClient : IHttpClientInternal;
802+
//begin
803+
// raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
804+
// FHttpMethod := THttpMethod.PUT;
805+
// entityType := TypeInfo(T);
806+
// returnType := TypeInfo(R);
807+
// lClient := GetClient;
808+
// response := lClient.Send(Self, cancellationToken );
809+
//
810+
// result := nil;
811+
//
812+
//end;
813+
//
814+
//function TRequest.Put<T>(const entity : T; const cancellationToken: ICancellationToken): IHttpResponse;
815+
//var
816+
// entityType : PTypeInfo;
817+
// lClient : IHttpClientInternal;
818+
//begin
819+
// raise ENotImplemented.Create('Serialization/Deserialization not implemented yet');
820+
// FHttpMethod := THttpMethod.PUT;
821+
// entityType := TypeInfo(T);
822+
//
823+
// //TODO : Serialize!
824+
// lClient := GetClient;
825+
// result := lClient.Send(self, cancellationToken);
826+
//end;
811827

812828
procedure TRequest.SetAccept(const value: string);
813829
begin

0 commit comments

Comments
 (0)