lundi 16 mars 2020

REST Api Reference Expansion

I have a SPA in Angular with which I need to show a collection of offices. Each row of the offices table has a tooltip showing a small list of employees and printers. How should I design the REST api (im using Spring)? I am in front of a crossroads:

1) use reference expansion:

/offices?expand=employees,printers

https://stripe.com/docs/api/expanding_objects https://opensource.zalando.com/restful-api-guidelines/#158

With this approach i will have to alter the database query (select * from offices + some left join for employees and printers). However if an user never hover its mouse on a offices row, I am serializing and transfering useless data.

2) dedicate endpoint

/offices/{id}/info

With this approach if an user never hover its mouse on a tooltip no request fires, otherwise I will have to use some caching mechanism to avoid too many requests to the server and manage the cache eviction on offices updates

Aucun commentaire:

Enregistrer un commentaire