Search code examples
web-servicesrestrestful-architecture

In REST how do you retrieve resources identified by 2 attributes?


In REST, if you want to retrieve a resource, you use something like: http://www.blabla.com/api/movies/1234 where 1234 is the unique identifier of the movie in the database. The question I have how do you retrieve entities from the database that are identified by 2 attributes? Maybe something like: http://www.blabla.com/api/grade/1234/764334532 (identified by the combination of user and exam id) Or perhaps I have to model the database or resources in other way, like adding an id to grades in the database. What do you think? Thanks.


Solution

  • If your exam id is globally unique you can just use that in the URI. no need to reference the user:

    http://www.blabla.com/api/exams/123
    

    if the exam id is only locally unique to a user, then you need to include both, as follows:

    http://www.blabla.com/api/users/456/exams/123