I have a resource that has a public and a private response, and only some users in determinant situations can access the private response.
What would be the best implementation?
resource/{id}
and resource/{id}/private
. resource/{id}
. resource/{id}?private=true
. Your terminology is a little mixed up. You have one resource, and multiple representation
s. The resource should have one canonical location (URL). It's perfectly fine for different users to get different representations based on their auth level.
If you want a user to be able to request a specific representation of the resource, you have a couple of options. If you're using custom MIME types, the Accept
header would be the best choice. A query parameter is your best bet if you're not using custom MIME types, but make sure it's something generic and consistent throughout the application. Don't just use ?private=true
, but instead use something like ?representation=public
. That allows you to add representations later and use the same parameter, and share the same query parameter with other resources that need to specify a representation. You should avoid using a separate URL.