❔ REST and Subresourses
I have two next entities
class Note{
public int Id {get;set}
public string Content
public int NotebookId {get;set}
public Notebook {get;set}
}
class Notebook{
public int Id {get;set}
public List<Note> Notes {get;set}
}
If I want to change some Note Content, how should the URL look like?
9 Replies
PATCH
or PUT
request to some /note
endpoint, with the note ID and new content being passed to itwhat about having /notebooks/id/notes/id/content?
Are you updating those, or the note?
Ah, I see what you mean
I mean, sure, you could have that kind of a monstrous route, why not
But I'd probably just have
notes/{id}/content
if anything
Unless note IDs are not unique in the scope of the database... but in that case it's just bad designthey are.
so it is ok to have “/content” corresponding to just a string field
I honestly wouldn't, as I said, I'd probably just use
/notes/{id}
or even just /notes
alone
If the note had more things to update, then sure, you might want a different endpoint for updating the content, for updating the tags, and so on
In your case, updating the content is updating the notegot it. thank you
Also, if I have 3 different DTO responses for one resource, how the URLs should look like? 👀
For example, if my frontend wants Note with just id and Name,
Note with just id, Name and Date created and
Note with content?
Probably
Naming is one of the biggest problems in programming lol
oh so it is really a thing, wow, omg
this solved so many problems
thank you!!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.