Middle
What is a resource-oriented model (ROM)?
sobes.tech AI
Answer from AI
Resource-Oriented Model — an approach to API design where the main entities of the system are represented as resources, which can be operated on using standard operations such as create, read, update, and delete (CRUD) with standard HTTP methods.
Key principles:
- Resources: The main components of the system, identified by a unique identifier (URI). For example, "user", "order", "product".
- Uniform interface: Using standard HTTP methods (GET, POST, PUT, PATCH, DELETE) to perform operations on resources.
- Resource identification: Each resource has a unique URI.
- Representations: Resources can have different representations (e.g., JSON, XML), agreed upon between client and server.
- Hypermedia (Links between resources): Resources can contain links to related resources, enabling clients to navigate the API.
Example:
// Get list of users
GET /users
// Get a specific user
GET /users/123
// Create a new user
POST /users
Content-Type: application/json
{
"name": "Ivan",
"email": "ivan@example.com"
}
// Update a user
PUT /users/123
Content-Type: application/json
{
"name": "Ivan Petrov"
}
// Partially update a user
PATCH /users/123
Content-Type: application/json
{
"email": "ivan.petrov@example.com"
}
// Delete a user
DELETE /users/123
Advantages:
- Simplicity and standardization: Easy to understand and use due to the application of standard web technologies.
- Scalability: Suitable for building distributed systems.
- Caching: Ability to cache resource representations to improve performance.
- Client-server independence: Separation of data presentation from storage and processing.
Disadvantages:
- May be inefficient for performing complex operations that do not fit into CRUD.
- Not always suitable for stateful services.
ROM is the foundation for building RESTful APIs.