REST get resource by two ids -
i have 2 entities: articles , users. users may write comment articles, specified user may write 1 comment specified article. so, comment can identified article_id
, user_id
.
the classic rest request comment is: /comment/:id
. in case don't have comment_id because useless. think /comment/:article_id/:user_id
or /comment/:article_id!:user_id
requests.
what best practice such cases?
i wouldn't call missing commentid 'useless', situation when need it. if @ possible, should create surrogate primary key (with no business meaning , created automatically db) in comments table - instead of compound key of userid + articleid.
this allow more flexibility when/if requirements change. perhaps users allowed post more comments or comments need threaded.
if database unchangeable legacy, agree urls given @gerino
Comments
Post a Comment