Junior — Middle
How to determine if an API conforms to RESTful architecture principles?
sobes.tech AI
Answer from AI
A RESTful API conforms to REST principles if the following key criteria are met:
- Use of HTTP methods as intended: GET for retrieving data, POST for creating, PUT/PATCH for updating, DELETE for deleting.
- Identification of resources via URI: each resource has a unique and understandable URL.
- Statelessness: each request contains all the necessary information, and the server does not store client state.
- Use of standard HTTP response codes: for example, 200 OK, 404 Not Found, 201 Created.
- Support for various representation formats (e.g., JSON, XML) via Accept/Content-Type headers.
You can verify this by analyzing the API for compliance with these principles and correct use of HTTP.
Example:
GET /users/123 HTTP/1.1
Host: example.com
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
{"id":123, "name":"Ivan"}