C
C#2y ago
bookuha

❔ 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
Angius
Angius2y ago
PATCH or PUT request to some /note endpoint, with the note ID and new content being passed to it
bookuha
bookuhaOP2y ago
what about having /notebooks/id/notes/id/content?
Angius
Angius2y ago
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 design
bookuha
bookuhaOP2y ago
they are. so it is ok to have “/content” corresponding to just a string field
Angius
Angius2y ago
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 note
bookuha
bookuhaOP2y ago
got 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?
Angius
Angius2y ago
Probably
GET: /note/{id} -> full note
GET: /note/{id}/basic -> name and ID
GET: /note/{id}/details -> name, ID, date
GET: /note/{id} -> full note
GET: /note/{id}/basic -> name and ID
GET: /note/{id}/details -> name, ID, date
Naming is one of the biggest problems in programming lol
bookuha
bookuhaOP2y ago
oh so it is really a thing, wow, omg this solved so many problems thank you!!
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server