rest - How do you RESTfully Create and Delete at the Same Time? -
let's have trip planning application, , each trip composed of "path" resources (representing route driven, example) composed series of points. can crud these resources using requests (just example):
post /trips/1234/paths <path> <point>32,32</point> <point>32,34</point> <point>34,34</point> </path> delete /trips/1234/paths/3
now consider want able split path 2 paths. in aobve example, might want pick point (32,34) split on, result in 2 paths - 1 ends @ point, 1 starts @ point. means single action creates 2 new resources, , simultaneously, deletes (the path split).
so if path in example above path in system, , split single call, system contain 2 new paths , original gone. example:
<path> <point>32,32</point> <point>32,34</point> </path> <path> <point>32,34</point> <point>34,34</point> </path>
i'm struggling how handled restfully. how 1 handle calls result in multiple resources being created/modified/deleted , communicate caller?
i can figure out multiple calls (two posts create new paths , delete remove original), want single call.
i try implement @darrel miller's answer yet make little less rpcish. idea create pathsplit resource guides client each step of way complete transaction. way client knows result of each step , knows hows out if there error along way.
something should trick.
post /pathsplit http/1.1 content-type: application/vnd.acme.pathsplit+xml <pathsplit xmlns="http://schema.acme.com"> <path> <id>123</id> </path> <splitpoint> <point>32,34</point> </splitpoint> </pathsplit> => http/1.1 201 created content-type: application/vnd.acme.pathsplit+xml location: http://acme.com/pathsplit/11 <pathsplit xmlns="http://schema.acme.com"> <path> <id>123</id> </path> <splitpoint> <point>32,34</point> </splitpoint> <newpaths> <path> <point>32,32</point> <point>32,34</point> </path> <path> <point>32,34</point> <point>34,34</point> </path> <createuri>http://acme.org/trips/paths</createuri> </newpaths> <oldpath> <uri>http://acme.org/trips/paths/123</uri> </oldpath> <status>in-progress</status> <pathscreated>0</pathscreated> </pathsplit>
with client can get
pathsplit resource see actions take. in example create both new paths
following createuri
link , sending post
request each new path
in newpaths
. server updates status each new resource created.
once status has pathscreated
of 2, client can delete old path
following uri , sending delete
verb. finally, delete pathsplit resource, indicating succeeded.
at every step along way, in case of error, or in common case of network outage, client knows state server in , state transaction in.
the pathsplit resource remains available long transaction hasn't completed. client has option of reverting transaction has not yet completed. again, since knows operations have completed , haven't, can out transaction.
Comments
Post a Comment