Home > OS >  Should a response to a GET request include URIs to other resources?
Should a response to a GET request include URIs to other resources?

Time:01-02

I'm currently writing a basic RESTful API to manage students, lectures and profs. It's a small project to understand REST better.

Now, in my database (NoSQL/MongoDB) I have students which are enrolled in lectures. To represent that relation, every student has an array of lecture IDs (The lectures primary keys).

When GETting a student from the API, should the lectures array contain only the ID/primary key, or the URI to fetch the lectures?

From what I understand, it should return the URIs, strictly RESTful speaking, is that correct?

Thanks!

CodePudding user response:

Should a response to a GET request include URIs to other resources?

Often, yes. See the world wide web - following links in hypertext documents is how we get around. Linking to common content (images, stylesheets) allows us to leverage caching and support "web scale".

But - it's a design choice; if following a link isn't a sensible thing to do, then the link probably shouldn't be there.

In some cases, it will make sense to use a URI template and arguments rather than explicitly listing resource identifiers. On the web, this will often look like an HTML form, with input controls that allow you to choose the arguments to be applied to the template.

It's trade offs all the way down.

  • Related