Sending a PATCH Request with Curl [C#/.NET Code]

To send a PATCH request using Curl, you need to 1) tell Curl to send a PATCH request by specifying the -X PATCH command line parameter, 2) pass the PATCH data with the -d command line parameter, and 3) provide the correct ContentType HTTP header with the -H command line parameter. The -X PATCH command line parameter tells Curl to use the HTTP PATCH method instead of POST. The -H 'Content-Type: application/json' command line parameter tells Curll to send an HTTP header to the server, indicating the data type in the PATCH message's body. In this Curl PATCH Request Example, we send a PATCH request to the ReqBin echo URL using the -X command-line option. Click Run to execute the Curl PATCH Request online and see the results. The C#/.NET code was automatically generated for the Curl PATCH Request example.
Sending a PATCH Request with Curl [C#/.NET Code] Run
curl -X PATCH https://reqbin.com/echo/patch/json
     -H 'Content-Type: application/json'
     -H 'Accept: application/json'
     -d '{"Id": 78912, "Customer": "Jason Sweet", "Quantity": 1}'
Updated: Viewed: 32411 times
C#/.NET code for Curl PATCH Request example

C#/.NET code for Curl PATCH Request Example

This C#/.NET 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:

Curl PATCH Request Syntax
curl -X PATCH [URL] 
     -H [header]
     -d [patch_data]

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 Example
curl -X PATCH https://reqbin.com/echo/patch/json
     -H 'Content-Type: application/json'
     -d '{"User": "Leo", "Id": 1}'

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:

Basic Curl PATCH request Example
curl -X PATCH https://reqbin.com/echo/patch/json
     -H 'Content-Type: [content type]'
     -d '[patch data]'

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:

Curl PATCH Request with JSON data Example
curl -X PATCH https://reqbin.com/echo/patch/json
     -H "Content-Type: application/json"
     -d '{"Id": 12345, "Price": 25}'

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:

Curl PATCH Request with XML data Example
curl -X PATCH https://reqbin.com/echo/patch/xml
     -H "Content-Type: application/xml"
     -d '<Order>
            <Id>14</Id>
            <Customer>UpdatedJason</Customer>
            <Price>35.00</Price>
         </Order>'

Sending a plain text with a PATCH request

The following is an example of sending plain text with a PATCH request method using Curl:

Curl PATCH Request with TEXT Data Example
curl -X PATCH https://reqbin.com
     -H "Content-Type: text/plain"
     -d 'some text'

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:

Curl PATCH Request with JSON File Example
curl -X PATCH https://reqbin.com/echo/patch/json
     -H "Content-Type: application/json"
     -d @data.json 

See also

Generate code snippets for C#/.NET and other programming languages

Convert your Curl PATCH Request request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the C#/.NET code generator.