On 31/10/17 09:24, sunlf wrote:
>
> Hi, devs,
>
>
>
> For C++ API, here are 2 functions, PUT and POST.
>
>
>
> What’s the difference between these 2?

Thanks for asking, because it's not obvious,
It worth to be confirmed, but I am not sure there is a direct mapping from
4 CRUD ops to POST, GET, PUT, DELETE verbs.

Before let me share some investigation I made,

In HTTP/REST world my understanding,
is that POST is (usually) for creating new (children) resources,
while PUT is (usually) for updating a fixed one,
but it's not that easy, check:

https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5
{
POST:
"The actual function performed by the POST method is *determined by the
server* and is usually dependent on the Request-URI."
If a resource *has been created *on the origin server, the response
SHOULD be 201 (Created) and contain an entity which describes the status
of the request and *refers to the new* resource, and a Location header


PUT:
If the Request-URI does not point to an existing resource,
and that URI is capable of being defined as *a new resource* by the
requesting user agent,
the origin server *can create* the resource with that URI
}

So it's server side to decide which strategy to use, (update can be done
using POST or PUT)

Similar in CoAP world:

https://tools.ietf.org/html/rfc7252#section-5.8.2

{
POST:

It usually results in *a new resource being created*

If the POST succeeds but does not result in a new resource being created on
the server, the response SHOULD have a 2.04 (Changed)

POST is neither safe nor idempotent.

PUT:

If a resource exists at the request URI, the enclosed representation
SHOULD be considered a modified version of that resource, and a 2.04
(Changed) Response Code SHOULD be returned.  If no resource exists,
then the server *MAY create a new resource* with that URI,

PUT is not safe but is idempotent.
}

Now in OCF/OIC world see: p115

https://openconnectivity.org/specs/OCF_Core_Specification_v1.0.0.pdf

Mapping is more clear and POST is only used for update,

UPDATE with POST,
CREATE with PUT new existing URL (or use POST to create sub EndPoints on
existing URL)

while POST on existing URL is not listed in the table,
(even if undetermined I guess it is assumed that iotivity do the same as
POST verb)

Note that most OneIoA models are using POST for update, this what you
will mostly use.

Confirmation is welcome, because it's still confusing
It will help to fix this pending bug regarding iotivity's examples
https://jira.iotivity.org/browse/IOT-948

Regards

-- 
mailto:philippe.co...@osg.samsung.com gpg:0x467094BC
https://blogs.s-osg.org/author/pcoval/

_______________________________________________
iotivity-dev mailing list
iotivity-dev@lists.iotivity.org
https://lists.iotivity.org/mailman/listinfo/iotivity-dev

Reply via email to