POST /notes/{note_id}/labels seems more intuitive to me. I would return HTTP 201 with location of label.
Regards,
Manoj
--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+...@googlegroups.com.
Visit this group at http://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/groups/opt_out.
In our API we need to add relationships from one object to another. I will translate it to the simple Note->Labels model.
POST /notes/{note_id}/labels
This is used to add a label to a note. Post data should include one of label_id or all information required to create a new label.What would you return in response? '200 OK' or '201 CREATED'. If CREATED than what URL should be in Location header? Label or Note?
Would you use different URL theme? For example
POST /labels to create a new label if requiredPUT /notes/{note_id}/labels/{label_id} with empty body to add relationship
PUT /note/123/label/456
I'm glad you brought up this.On Fri, Oct 25, 2013 at 4:58 AM, Vladimir Prudnikov <v.pru...@gmail.com> wrote:
In our API we need to add relationships from one object to another. I will translate it to the simple Note->Labels model.POST /notes/{note_id}/labels
This is used to add a label to a note. Post data should include one of label_id or all information required to create a new label.What would you return in response? '200 OK' or '201 CREATED'. If CREATED than what URL should be in Location header? Label or Note?Does the label already exist?
Can a label can belong to more than one note? That's important in this discussion. I'll assume that is the case.
Would you use different URL theme? For example
POST /labels to create a new label if requiredPUT /notes/{note_id}/labels/{label_id} with empty body to add relationshipYes, that's what I do. POST /label (I'm in the singular-noun camp) to create a label if it does not exist yet. I would return Location with the URL and also an ID.
Let's reason../notes/{note_id}/labels is endpoint for Note.labels *collection*. In a REST world sending POST request to a collection endpoint should create a *new* object of this collection's object type. And I think in this case we should create a new label AND a relationship. Right?
POST /notes/{note_id}/labels
POST /labels (posting label data to create the new label)PUT /notes/{notes_id}/labels/{labels_id}
POST /labels/{labels_id}/notes
So, we should always send whole label with POST request and this label SHOULD NOT prior to sending this request, hence, we can't use this endpoint with POST request to add a relationship with the existing label.
An alternative request to create a relationship with an existing object is PATCH /notes/{note_id}/labels.
On Fri, Oct 25, 2013 at 6:58 AM, Vladimir Prudnikov <v.pru...@gmail.com> wrote:
Let's reason../notes/{note_id}/labels is endpoint for Note.labels *collection*. In a REST world sending POST request to a collection endpoint should create a *new* object of this collection's object type. And I think in this case we should create a new label AND a relationship. Right?SoPOST /notes/{note_id}/labelsis really a short-cut for doing these two separate operations?POST /labels (posting label data to create the new label)PUT /notes/{notes_id}/labels/{labels_id}Then would you also have this short-cut to create a note and associate it with a single label? It's many-to-many, after all.
POST /labels/{labels_id}/notesAnother question: If you use PUT as above to create the relationship it would be reasonable to return the URL of the relationship, right? Then you can later DELETE it. if you use the short-cut to create both the new label and the new label-note relationship in a single POST what gets returned?
Another option is to PUT a note and include a list of associated labels. I don't like that approach.
So, we should always send whole label with POST request and this label SHOULD NOT prior to sending this request, hence, we can't use this endpoint with POST request to add a relationship with the existing label.
If I understand what you are saying, yes, that's why I don't like the POST short-cut method.An alternative request to create a relationship with an existing object is PATCH /notes/{note_id}/labels.Good question. Is a label really an attribute of a note?