Python code for Curl PATCH Request Example
This Python code snippet was generated automatically for the Curl PATCH Request example.<< Back to the Curl PATCH Request example
What is Curl?
Curl is a command-line utility for transferring data to or from a remote server. Curl is used for API testing, sending files to the server, and viewing the server response headers. Curl supports over 25+ protocols, including HTTP, HTTPS, FTP, FTPS, and SFTP, has built-in support for SSL certificates, HTTP Cookies, and more.
What is HTTP PATCH?
The PATCH method is one of 9 commonly used Hypertext Transfer Protocol (HTTP) request methods to modify an existing resource partially. The PATCH method sends an object containing partial data and rules for applying this data to an existing resource identified by its URI. For a PATCH request, we don't need to provide all the data. We only send the data that we want to update. The main difference from the HTTP PUT method is that the HTTP PATCH method partially replaces the resource, while the HTTP PUT method completely replaces the resource. PATCH is somewhat similar to the concept of "update" in CRUD.
Curl PATCH Request Syntax
The general form of the Curl command for sending a PATCH request is as follows:
How to send a PATCH request using Curl?
To make a PATCH request using Curl, you need to use the -X command-line option, specify the PATCH method, and pass the data type in the request's body.
Curl PATCH Request Examples
The following are examples of sending PATCH requests:
Basic PATCH request example
The following is a basic example of sending a PATCH request to the ReqBin echo URL:
Sending JSON data with a PATCH request
To send JSON using Curl, you must pass the JSON data with the -d command line parameter and specify the correct MIME data type in the request body using the -H 'Content-Type: application/json' command line parameter. The following is an example of sending JSON data with the PATCH request method using Curl:
Sending XML data with a PATCH request
To send XML using Curl, pass the XML data with the -d command line parameter and specify the correct MIME data type in the request body using the -H 'Content-Type: application/xml' command line parameter. The following is an example of sending XML data with the PATCH request method using Curl:
Sending a plain text with a PATCH request
The following is an example of sending plain text with a PATCH request method using Curl:
Sending a file with PATCH requests
The following is an example of sending data from a file in the body of a CURL PATCH request: