Sending PUT Request with JSON

To put JSON data to the server, you need to make an HTTP PUT request to the server, specify the correct MIME data type for the JSON, and provide the JSON data in the body of the PUT message. The correct MIME type for JSON is application/json. In this PUT JSON to the Server example, we are making an HTTP PUT request to the ReqBin echo URL. The Content-Type: application/json request header specifies the media type for JSON in the body of the HTTP PUT message, and the Accept: application/json request header tells the server that the client is expecting JSON in the server's response. Click Send to execute the PUT JSON request example online and see the results.
Sending PUT Request with JSON Send
PUT /echo/put/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 81

{
  "Id": 78912,
  "Customer": "Jason Sweet",
  "Quantity": 1,
  "Price": 18.00
}
Updated: Viewed: 29312 times

What is JSON?

JSON (JavaScript Object Notation) is a language-independent format for storing and exchanging data. The JSON format is used with almost any programming language and API. JSON is widely used by web applications to exchange data between a web browser and a server and exchange data between servers via REST or JSON APIs. The JSON format is well suited for serializing complex and large data structures. JSON files can contain only text, not take up much disk space, and have a .json extension.

What is HTTP?

Hypertext Transfer Protocol (HTTP) is a network data transfer protocol that enables the communication between HTTP clients (browser or mobile application) and servers. HTTP is built on request-response messages between a client and a server. The client sends a request to the server, then the server processes this request and sends a response back to the client.

What is the HTTP PUT method used for?

The HTTP PUT request method is used to update an existing resource on the server. You can send any data in the body of the PUT request. Data type and size are not limited. The PUT request method is defined as idempotent, which means that multiple identical PUT requests should have the same effect as a single request (do not cause any changes in data).

To update an existing resource on the server, the client must provide a JSON that contains mutable fields with new values. If the requested object does not exist, the server can create it. In this case, the server informs the client that the resource has been created with a 201 (Created) status code in response to the PUT request. If the requested resource is successfully updated, the server will return 200 (OK) or 204 (No Сontent) status codes.

PUT JSON Example

The following is an example of sending JSON data to ReqBin echo URL using the HTTP PUT method:

PUT JSON Request Example
PUT /echo/put/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 81

{
  "Id": 78912,
  "Customer": "Jason Sweet",
  "Quantity": 1,
  "Price": 18.00
}

Server response to our PUT request:

Server Response to PUT Request
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19

{"success":"true"}

See also

Generate Code Snippets for PUT JSON Example

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