TsgcHTTP2ClientMethods › Patch

Patch Method

Performs a synchronous HTTP/2 PATCH, applying a partial modification to the target resource.

Overloads

Overload 1

Syntax

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

Parameters

NameTypeDescription
aURLconst stringAbsolute URL of the resource to be partially updated.
aSourceconst TStreamStream holding the patch document (for example a JSON Patch or JSON Merge Patch body).

Return Value

Response body returned by the server decoded as a string. (string)

Remarks

Unlike PUT, PATCH sends only the fields that should change. Ensure Request.ContentType matches the patch format expected by the server (e.g. application/json-patch+json or application/merge-patch+json).

Example

oBody := TStringStream.Create('{"email":"new@example.com"}');
try
  oClient.Request.ContentType := 'application/merge-patch+json';
  vResponse := oClient.Patch('https://api.example.com/users/42', oBody);
finally
  oBody.Free;
end;

Overload 2

Syntax

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

Parameters

NameTypeDescription
aURLconst stringAbsolute URL of the resource to be partially updated.
aSourceconst TStreamStream containing the patch payload.
aResponseContentconst TStreamStream that captures the raw response from the server.

Remarks

Fully streamed variant. Suitable when the patch document or the response representation is large enough that a string round-trip would be wasteful.

Example

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

Back to Methods