uses
sgcHTTP, sgcHTTP_Server, sgcHTTP_Gateway;
var
Server: TsgcHTTPServer;
HTTP2: TsgcHTTP2Client;
GRPC: TsgcGRPCClient;
begin
Server := TsgcHTTPServer.Create(nil);
Server.Port := 8080;
Server.DocumentRoot := 'C:\www';
Server.OnCommandGet := ServerCommandGet;
Server.Active := True;
FGateway := TsgcHTTPGateway.Create(nil);
FGateway.Handlers.Add('*.php', 'fcgi://127.0.0.1:9000');
FGateway.Handlers.Add('/app/', 'scgi://127.0.0.1:4000');
HTTP2 := TsgcHTTP2Client.Create(nil);
HTTP2.Host := 'https://api.example.com';
HTTP2.OnHTTP2Response := HTTP2Response;
HTTP2.Active := True;
HTTP2.GetAsync('/v1/status');
GRPC := TsgcGRPCClient.Create(nil);
GRPC.Client.Host := 'https://grpc.example.com';
GRPC.OnGRPCResponse := GRPCResponse;
GRPC.CallAsync('example.OrderService', 'GetOrder', RequestBytes);
end;
procedure TForm1.HTTP2Response(Sender: TObject;
const Connection: TsgcHTTP2ConnectionClient;
const Request: TsgcHTTP2RequestProperty;
const Response: TsgcHTTP2ResponseProperty);
begin
Memo1.Lines.Add(Response.DataString);
end;
procedure TForm1.GRPCResponse(Sender: TObject;
const aResponse: TsgcGRPCResponse);
begin
Memo1.Lines.Add(aResponse.DataString);
end;
procedure TForm1.ServerCommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
if FGateway.Process(AContext, ARequestInfo, AResponseInfo) then
Exit;
if ARequestInfo.Document = '/api/status' then
begin
AResponseInfo.ContentType := 'application/json';
AResponseInfo.ContentText := '{"status":"ok"}';
end;
end;
TsgcHTTPServer *Server = new TsgcHTTPServer(this);
Server->Port = 8080;
Server->DocumentRoot = "C:\\www";
Server->OnCommandGet = ServerCommandGet;
Server->Active = true;
FGateway = new TsgcHTTPGateway(this);
FGateway->Handlers->Add("*.php", "fcgi://127.0.0.1:9000");
FGateway->Handlers->Add("/app/", "scgi://127.0.0.1:4000");
TsgcHTTP2Client *HTTP2 = new TsgcHTTP2Client(this);
HTTP2->Host = "https://api.example.com";
HTTP2->OnHTTP2Response = HTTP2Response;
HTTP2->Active = true;
HTTP2->GetAsync("/v1/status");
TsgcGRPCClient *GRPC = new TsgcGRPCClient(this);
GRPC->Client->Host = "https://grpc.example.com";
GRPC->OnGRPCResponse = GRPCResponse;
GRPC->CallAsync("example.OrderService", "GetOrder", RequestBytes);
void __fastcall TForm1::HTTP2Response(TObject *Sender,
const TsgcHTTP2ConnectionClient* Connection,
const TsgcHTTP2RequestProperty* Request,
const TsgcHTTP2ResponseProperty* Response)
{
Memo1->Lines->Add(Response->DataString);
}
void __fastcall TForm1::GRPCResponse(TObject *Sender,
const TsgcGRPCResponse* aResponse)
{
Memo1->Lines->Add(aResponse->DataString);
}
void __fastcall TForm1::ServerCommandGet(TIdContext *AContext,
TIdHTTPRequestInfo *ARequestInfo, TIdHTTPResponseInfo *AResponseInfo)
{
if (FGateway->Process(AContext, ARequestInfo, AResponseInfo))
return;
if (ARequestInfo->Document == "/api/status")
{
AResponseInfo->ContentType = "application/json";
AResponseInfo->ContentText = "{\"status\":\"ok\"}";
}
}