Middle
What HTTP methods do you know? How do PATCH and PUT differ? What happens if a PUT request is made to a resource that does not exist in the database? Is it possible to pass data via GET? How do POST and PUT differ? What is idempotency?
sobes.tech AI
Answer from AI
Main HTTP methods:
- GET — retrieve a resource
- POST — create a resource
- PUT — replace a resource
- PATCH — partially update a resource
- DELETE — delete a resource
- OPTIONS — find out supported methods
Differences between PATCH and PUT:
- PUT replaces the entire resource.
- PATCH modifies only specified fields, partial update.
If a PUT request is made to a resource with a non-existent ID:
- Usually, the server creates a new resource with that ID (if the API supports it), otherwise it returns an error.
Can data be transmitted via GET?
- Yes, through URL parameters (query string), but it is not recommended for sensitive or large data.
Differences between POST and PUT:
- POST creates a new resource, is not idempotent (repeating the request will create multiple resources).
- PUT is idempotent, replaces the resource at the specified URI.
Idempotency:
- A property of an operation where repeated execution yields the same result as a single execution. For example, PUT and DELETE are idempotent, POST is not.