Reputation: 1115
I'm designing a REST API where I need to give the clients the ability to copy resources. Say for example you have the following resource: customer/{customerno}/address
And you will provide the client with functionallity for copying the address to shippingaddress. I could do like this: customer/{customerno}/address/copytoshipping
But then it would be RPC and not REST. What is the correct way to do something like this?
Upvotes: 2
Views: 295
Reputation: 906
A different approach could be:
Expose a resource for "customer address" (as you stated above)
GET /customer/{number}/address
Expose a resource for "customer shipping address" fetch:
GET /customer/{number}/shipping-address
update with actual address:
PUT /customer/{number}/shipping-address
Content-Type: application/xml
(xml/json of a single address)
update using a URI pointer to another address
PUT /customer/number/shipping-address HTTP/1.1
Content-Type: application/atom+xml
(xml/json of an atom:link with href pointer to main address ('/customer/123/address')
Perhaps more complex than you want but puts the copy burden on the server rather than the client.
Upvotes: 1
Reputation: 137797
Does that have to be in the REST API? The client could just GET the representation of the (billing?) address and PUT it to the shipping address. Yes, you might well hide the details of that in your client-side code (that seems very reasonable to me) but there's no particular reason to clutter the REST interface with special operations to do the copying.
Upvotes: 2
Reputation: 2878
GET the address using Rel="CustomerAddress"
POST using Rel="CustomerShippingAddress" example URL customer/{customerno}/address/shipping
Upvotes: 1