The command
curl -X PATCH https://httpbin.org/patch \
-H "Content-Type: application/json" \
-d '{"role":"admin"}'
Opens the request console with this request filled in. It is sent from api-tester.com's server rather than from your machine, so it shows what the endpoint returns, not how your own network or curl build behaves.
What the flags do
| Flag | What it does |
|---|---|
-X PATCH | Set the method. Curl has no dedicated PATCH flag. |
-d data | The patch document. |
-H "Content-Type: ..." | Tells the server which patch format the body uses. |
Two patch formats, two media types
Most JSON APIs accept a partial object and merge it: fields present are updated, fields absent are left alone. That is JSON Merge Patch (application/merge-patch+json), although many servers accept it under plain application/json. Its one sharp edge: null means "delete this field", so you cannot use it to set a value to null, and arrays are replaced whole.
JSON Patch (application/json-patch+json) is a list of operations instead. It can append to an array, move a value, or test a value before changing it, at the cost of being more verbose.
# JSON Merge Patch: change role, remove nickname
curl -X PATCH https://api.example.com/users/42 \
-H "Content-Type: application/merge-patch+json" \
-d '{"role":"admin","nickname":null}'
# JSON Patch: a list of operations
curl -X PATCH https://api.example.com/users/42 \
-H "Content-Type: application/json-patch+json" \
-d '[{"op":"replace","path":"/role","value":"admin"},
{"op":"add","path":"/tags/-","value":"beta"}]'
PATCH is not automatically safe to retry
Unlike PUT, a PATCH is not guaranteed to be idempotent. Setting role to admin twice is harmless, but an operation such as "append to this list" or "increment this counter" is applied again on a retry. If a request times out and you cannot tell whether it landed, read the resource before sending it again, or use If-Match with the ETag you last saw.
Common mistakes
- Sending a JSON Patch array as
application/jsonusually gets a400or415: the server tries to merge an array into an object. 405 Method Not Allowedmeans the endpoint does not implement PATCH at all. Check theAllowresponse header for what it does accept.- Shell quoting. Wrap the JSON in single quotes on Linux and macOS; on Windows read the body from a file with
-d @patch.json.
Related curl examples
Curl PUT Example
PUT replaces the resource at a URL with the body you send.
Curl POST JSON Example
Sending JSON takes two things: the JSON itself and a header saying that is what it is.
Curl Content-Type Example
Content-Type tells the server how to parse the body you sent.
Curl DELETE Request Example
Deleting with curl is one flag.
All Curl Examples
49 worked examples, grouped by what you are trying to do.
More under Methods
References
- curl man page: -X — Setting a custom request method.
- MDN: PATCH — Partial updates and why PATCH is not necessarily idempotent.
- RFC 7396: JSON Merge Patch — The merge format most JSON APIs accept.
These links leave api-tester.com, which is independent of the projects they point to.
FAQ
How do I send a PATCH request with curl?
Use -X PATCH with a body and a Content-Type header, for example curl -X PATCH -H "Content-Type: application/json" -d '{"role":"admin"}' URL.
What Content-Type should a PATCH request use?
application/merge-patch+json for a partial object to merge, or application/json-patch+json for a list of operations. Many APIs also accept application/json for merge-style patches.
What is the difference between PATCH and PUT?
PUT replaces the whole resource with the body. PATCH applies a partial change and leaves the fields you did not mention as they were.