Creating a resource with HTTP method PUT on Structr REST interface?

33 views
Skip to first unread message

Bernhard Dellith

unread,
Jan 22, 2016, 3:57:46 PM1/22/16
to structr
Hello,

I tested the following Structr REST HTTP PUT request to an existing database type "Device" which had no resource instances:

curl -i -HX-User:admin -HX-Password:admin -XPUT \
http://server:8082/structr/rest/devices/2dfdc6fc2d4b435ca7ec9e5c22d7725d \
-d {"name":"device123","model_Id":"987654"}

I received an "HTTP/1.1 404 Not Found" response.

In contrast to that I would expect a response "201 Created".

When the resource with the requested id already exists in the database the same PUT request works fine and modifies the data fields of the resource as expected.

Am I wrong or is it not implemented in Structr?

The RFC 2616 "Hypertext Transfer Protocol -- HTTP/1.1" says on page 54, paragraph "9.6 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. If a
   new resource is created, the origin server MUST inform the user agent
   via the 201 (Created) response."

Thanks and
Best regards
Bernhard

Christian Morgner

unread,
Jan 22, 2016, 7:15:51 PM1/22/16
to str...@googlegroups.com
Hi Bernhard,

please use POST to create new entities. In Structr, PUT can only be used to modify resources that already exist.

Best regards,
Christian



Am 22.01.2016 um 21:57 schrieb Bernhard Dellith:
> Hello,
>
> I tested the following Structr REST HTTP PUT request to an existing database type "Device" which had no resource instances:
>
> curl -i -HX-User:admin -HX-Password:admin -XPUT \
> http://server:8082/structr/rest/devices/2dfdc6fc2d4b435ca7ec9e5c22d7725d \
> -d {"name":"device123","model_Id":"987654"}
>
> I received an "HTTP/1.1 404 Not Found" response.
>
> In contrast to that I would expect a response "201 Created".
>
> When the resource with the requested id already exists in the database the same PUT request works fine and modifies the data fields of the resource as expected.
>
> Am I wrong or is it not implemented in Structr?
>
> The RFC 2616 "Hypertext Transfer Protocol -- HTTP/1.1" says on page 54, paragraph "9.6 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. If a
> new resource is created, the origin server MUST inform the user agent
> via the 201 (Created) response."
>
> Thanks and
> Best regards
> Bernhard
>
> --
> You received this message because you are subscribed to the Google Groups "structr" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com <mailto:structr+u...@googlegroups.com>.
> To post to this group, send email to str...@googlegroups.com <mailto:str...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/structr.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/structr/ca08b393-31ad-4ce3-9f7e-d1a2c2ed5de3%40googlegroups.com <https://groups.google.com/d/msgid/structr/ca08b393-31ad-4ce3-9f7e-d1a2c2ed5de3%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Christian Morgner
CTO Structr GmbH · Hanauer Landstr. 291a · 60314 Frankfurt · Germany
Phone: +49 163 2536088
Twitter: @cmor_

http://structr.com

Reply all
Reply to author
Forward
0 new messages