TsgcHTTP2ClientMethods › Put

Put Method

Performs a synchronous HTTP/2 PUT, replacing the resource at the URL with the uploaded content.

Overloads

Overload 1

Syntax

function Put(const aURL: string; const aSource: TStream): string;

Parameters

NameTypeDescription
aURLconst stringAbsolute URL identifying the resource that will be created or replaced.
aSourceconst TStreamStream supplying the full representation of the resource to store.

Return Value

Response body received from the server decoded as a string. (string)

Remarks

PUT is idempotent: calling it repeatedly with the same body yields the same resource state on the server. This overload is suited to JSON / text payloads whose textual response can be consumed as a string.

Example

oBody := TStringStream.Create('{"status":"active"}');
try
  oClient.Request.ContentType := 'application/json';
  vResponse := oClient.Put('https://api.example.com/users/42', oBody);
finally
  oBody.Free;
end;

Overload 2

Syntax

procedure Put(const aURL: string; const aSource: TStream; const aResponseContent: TStream);

Parameters

NameTypeDescription
aURLconst stringAbsolute URL identifying the resource to create or replace.
aSourceconst TStreamStream supplying the resource bytes to upload.
aResponseContentconst TStreamStream that captures the raw response body from the server.

Remarks

Stream-to-stream variant recommended for binary resource uploads, such as image or file replacements, where both the request and the response are best handled without string conversion.

Example

oIn := TFileStream.Create('avatar.png', fmOpenRead);
oOut := TMemoryStream.Create;
try
  oClient.Put('https://api.example.com/users/42/avatar', oIn, oOut);
finally
  oOut.Free;
  oIn.Free;
end;

Back to Methods