torrust-index
torrust-index copied to clipboard
Decouple API resources from internal structures
The API endpoints return internal objects, for example:
The endpoint to get all categories:
http://127.0.0.1:3000/v1/category
returns the struct Category:
pub struct Category {
pub category_id: i64,
pub name: String,
pub num_torrents: i64,
}
That's only one example.
That has some problems:
- If you change the internal representation, you can break the API unintentionally.
- You cannot change the API resources and the internal objects independently. For example, it will be harder to implement version 2 for the API.
- In the future, the API resource could contain different data.
- It's harder to mock the API responses if those objects have extra logic, ar nested, etcetera.
We could change it progressively or when we implement the API v2.
Subtasks
- [x] https://github.com/torrust/torrust-index/issues/501
@da2ce7 and @WarmBeer any comments?