Sobes.tech
Junior — Middle

What types of requests can you name and how do they differ?

sobes.tech AI

Answer from AI

Main types of HTTP requests (methods) that are commonly used:

  • GET — requests data from the server without changing the state. For example, retrieving a page or a list of users.
  • POST — sends data to the server to create a new record, such as user registration.
  • PUT — fully updates an existing resource.
  • PATCH — partially updates a resource.
  • DELETE — deletes a resource.

The difference is that GET is safe and idempotent (does not change data), while POST changes the server state. PUT and PATCH differ in the level of update: PUT replaces the entire resource, PATCH only a part.

Example in Python using requests:

import requests

response = requests.get('https://api.example.com/users')
print(response.json())

new_user = {'name': 'Alice', 'email': 'alice@example.com'}
response = requests.post('https://api.example.com/users', json=new_user)
print(response.status_code)