torrust-index icon indicating copy to clipboard operation
torrust-index copied to clipboard

Decouple API resources from internal structures

Open josecelano opened this issue 2 years ago • 1 comments

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

josecelano avatar May 25 '23 08:05 josecelano

@da2ce7 and @WarmBeer any comments?

cgbosse avatar Jan 16 '24 15:01 cgbosse