How to put JSON data on the Server? [Curl/Bash Code]
To put JSON data to the server, you need to make an HTTP PUT request to the server and specify the correct MIME type for the JSON in the PUT request body. The correct MIME type for JSON is application/json. In this PUT JSON example, 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. In this PUT JSON to the Server example, we are making an HTTP PUT request to the ReqBin echo URL. The Curl/Bash code was automatically generated for the PUT JSON example.
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
An example of sending JSON data to ReqBin echo URL using the HTTP PUT method: