0

What's the best approach to bring information about an object in a Rest API?

  1. All the entire object always:

    Request:
    GET /user/{idUser}
    
    Response:
    {
    id,
    name,
    birthday,
    street,
    city,
    state,
    country
    }
    
  2. Part that matters in an object, identified by context:

    Request:
    GET /user/address/{idUser}
    
    Response:
    {
    id,
    street,
    city,
    state,
    country
    }
    
Sergio Pantano
  • 111
  • 1
  • 10

1 Answers1

0

(2) should be avoided because it leads to a proliferation of endpoints. (1) is acceptable, but may be a performance hit because it pushes more information than is required over the wire. If you test the performance and find it unacceptable, you can provide something like this:

GET /users/bob?fields=id,street,city,state,country
{
    id,
    street,
    city,
    state,
    country
}
Eric Stein
  • 13,209
  • 3
  • 37
  • 52