rest - Handling CRUD on child objects with RESTful -


if given following xml request sent restful api endpoint called /catalog via put (intent update catalog).

if user provides additional <book>s don't exist @ point in catalog in request should endpoint "create" them? or should ignored , different endpoint perhaps /books used create them.

<?xml version="1.0"?> <catalog>    <book id="bk101">       <author>gambardella, matthew</author>       <title>xml developer's guide</title>       <genre>computer</genre>       <price>44.95</price>       <publish_date>2000-10-01</publish_date>       <description>an in-depth @ creating applications        xml.</description>    </book>    <book id="bk102">       <author>ralls, kim</author>       <title>midnight rain</title>       <genre>fantasy</genre>       <price>5.95</price>       <publish_date>2000-12-16</publish_date>       <description>a former architect battles corporate zombies,        evil sorceress, , own childhood become queen        of world.</description>    </book>    <book id="bk103">       <author>corets, eva</author>       <title>maeve ascendant</title>       <genre>fantasy</genre>       <price>5.95</price>       <publish_date>2000-11-17</publish_date>       <description>after collapse of nanotechnology        society in england, young survivors lay        foundation new society.</description>    </book>    <book id="bk104">       <author>corets, eva</author>       <title>oberon's legacy</title>       <genre>fantasy</genre>       <price>5.95</price>       <publish_date>2001-03-10</publish_date>       <description>in post-apocalypse england, mysterious        agent known oberon helps create new life        inhabitants of london. sequel maeve        ascendant.</description>    </book>    <book id="bk105">       <author>corets, eva</author>       <title>the sundered grail</title>       <genre>fantasy</genre>       <price>5.95</price>       <publish_date>2001-09-10</publish_date>       <description>the 2 daughters of maeve, half-sisters,        battle 1 control of england. sequel        oberon's legacy.</description>    </book>    <book id="bk106">       <author>randall, cynthia</author>       <title>lover birds</title>       <genre>romance</genre>       <price>4.95</price>       <publish_date>2000-09-02</publish_date>       <description>when carla meets paul @ ornithology        conference, tempers fly feathers ruffled.</description>    </book>    <book id="bk107">       <author>thurman, paula</author>       <title>splish splash</title>       <genre>romance</genre>       <price>4.95</price>       <publish_date>2000-11-02</publish_date>       <description>a deep sea diver finds true love twenty        thousand leagues beneath sea.</description>    </book>    <book id="bk108">       <author>knorr, stefan</author>       <title>creepy crawlies</title>       <genre>horror</genre>       <price>4.95</price>       <publish_date>2000-12-06</publish_date>       <description>an anthology of horror stories roaches,       centipedes, scorpions  , other insects.</description>    </book>    <book id="bk109">       <author>kress, peter</author>       <title>paradox lost</title>       <genre>science fiction</genre>       <price>6.95</price>       <publish_date>2000-11-02</publish_date>       <description>after inadvertant trip through heisenberg       uncertainty device, james salway discovers problems        of being quantum.</description>    </book>    <book id="bk110">       <author>o'brien, tim</author>       <title>microsoft .net: programming bible</title>       <genre>computer</genre>       <price>36.95</price>       <publish_date>2000-12-09</publish_date>       <description>microsoft's .net initiative explored in        detail in deep programmer's reference.</description>    </book>    <book id="bk111">       <author>o'brien, tim</author>       <title>msxml3: comprehensive guide</title>       <genre>computer</genre>       <price>36.95</price>       <publish_date>2000-12-01</publish_date>       <description>the microsoft msxml3 parser covered in        detail, attention xml dom interfaces, xslt processing,        sax , more.</description>    </book>    <book id="bk112">       <author>galos, mike</author>       <title>visual studio 7: comprehensive guide</title>       <genre>computer</genre>       <price>49.95</price>       <publish_date>2001-04-16</publish_date>       <description>microsoft visual studio 7 explored in depth,       looking @ how visual basic, visual c++, c#, , asp+        integrated comprehensive development        environment.</description>    </book> </catalog> 

i finding lot on talks put vs post , best practices doing crud operations on root object i've spent night trying find information around how child objects should handled.

according http://www.w3.org/protocols/rfc2616/rfc2616-sec9.html isn't clear me if applies child objects?

9.6 put

the put method requests enclosed entity stored under supplied request-uri. if request-uri refers existing resource, enclosed entity should considered modified version of 1 residing on origin server. if request-uri not point existing resource, , uri capable of being defined new resource requesting user agent, origin server can create resource uri. if new resource created, origin server must inform user agent via 201 (created) response. if existing resource modified, either 200 (ok) or 204 (no content) response codes should sent indicate successful completion of request. if resource not created or modified request-uri, appropriate error response should given reflects nature of problem. recipient of entity must not ignore content-* (e.g. content-range) headers not understand or implement , must return 501 (not implemented) response in such cases.

from understanding of rest, books resources , should handled through own endpoint , update catalog should used add existing books catalog, not create them.

so in scenario book not exist ignored/not added catalog until create request submitted create book.

this mean user send post /book create book, followed put /catalog book in request add catalog.

you're right. have 2 different resources here. 1 named books , other named catalogs. must design 2 different uris address each one. in scenario, i'd create 2 different resources handle problem. first resource named /catalogs , must build receive book id (one or more) wants associate catalog. you'll have:

endpoint -> https://yourapi.com/catalogs  post https://yourapi.com/catalogs --> creates new catalog. put https://yourapi.com/catalogs/1 --> updates catalog id = 1. put https://yourapi.com/catalogs/2 id 2 doesn't exist --> creates new catalog id=2 

you have send xml below endpoint pointed above.

<?xml version="1.0"?> <catalog>     <book id="bk101"/>     <book id="bk102"/>     <book id="bk103"/>     <book id="bk104"/> <catalog> 

the second resource should /books , must use create, delete, update , list books. once you've created book, can associate catalog. shouldn't use resource catalogs create book way. mind, doesn't make sense.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -