mardi 5 mai 2015

Best practices for REST-API models

I am working on a REST-API and have run into an architectural problem.

The model 'Book' represents a single book with properties and CRUD-based functions. It loads itself from a database via a read function.

However, what if I want to get all books in the database? The current book model does not cover this use case.

I have tried several approaches:

1.) A second model called 'Books'. It has a read function which returns a list of book objects.

2.) The model 'Book' itself has a readAll function which loads all books.

3.) The model 'Book' is non-functional, it only has properties. Instead a 'BookStorage' class loads the data and fills one/multiple models.

I am not satisfied with any of these approaches. Is there a best practice for this scenario?

Aucun commentaire:

Enregistrer un commentaire