Junior — Middle
Can you explain what an HTTP PUT request means?
sobes.tech AI
Answer from AI
The HTTP PUT request is used to create or replace a resource at the specified URL. Unlike POST, which typically creates a new resource, PUT sends a complete representation of the resource and saves it at a specific address.
Main characteristics of PUT:
- Idempotency: repeated requests with the same data do not change the result.
- Used for updating an existing resource or creating a new one if it does not exist.
Example of using PUT in Python with the requests library:
import requests
url = 'https://api.example.com/items/123'
data = {'name': 'New item', 'price': 100}
response = requests.put(url, json=data)
print(response.status_code)
In this example, we send data to create or update a resource with id 123.