Sobes.tech
Junior

What methods of data transmission to the server do you know?

sobes.tech AI

Answer from AI

  • GET: Sends data in the URL as query parameters. Used for requesting data without changing the server state. Data is visible in the address bar and has size limitations.
  • POST: Sends data in the request body. Used for sending data that may change the server state (creation, update). Data is not visible in the URL and has no strict size limitations. More secure for transmitting confidential information.
  • PUT: Used for updating a resource on the server or creating a new one if it does not exist. Update/create data is sent in the request body. Considered idempotent (multiple executions give the same result as a single one).
  • DELETE: Used to delete a resource from the server. Usually does not send a request body; the resource identifier is specified in the URL. Considered idempotent.
  • PATCH: Used for partial updates of a resource on the server. Differs from PUT in that it sends only the changes, not the entire resource data.

Examples of usage:

// GET request
GET /users?id=123&status=active HTTP/1.1
Host: example.com
// POST request
POST /users HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 45

{
  "name": "John Doe",
  "email": "john.doe@example.com"
}
// PUT request
PUT /users/123 HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 45

{
  "name": "John Doe",
  "email": "john.doe.updated@example.com"
}
// DELETE request
DELETE /users/123 HTTP/1.1
Host: example.com
// PATCH request
PATCH /users/123 HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 19

{
  "email": "john.doe.new@example.com"
}