Sobes.tech
Senior

What are HTTP methods? Describe the main methods and their purpose.

sobes.tech AI

Answer from AI

HTTP methods are standardized ways for a client to interact with a server in the HTTP protocol. They define the action that the client wants to perform on a resource.

Main methods:

  • GET — request to retrieve data from the server. Safe and idempotent method, should not change the server's state.
  • POST — send data to the server to create a new resource or perform an operation. Can change the server's state.
  • PUT — replace or create a resource at the specified URL. Idempotent method.
  • DELETE — delete a resource at the URL. Idempotent.
  • PATCH — partial update of a resource.
  • HEAD — request only the headers of a resource, without the body.

Example usage in Python with requests:

import requests
response = requests.get('https://api.example.com/items')
print(response.status_code, response.json())