Good REST design

Topics: Web Api
May 18, 2011 at 7:47 AM

Appologies if this is a bit off topic for this forum, but...

 



If I have a resource that can be marked as active or inactive and I have the following uri template

 

/MyResources/{id}

GET - Retrieve an individual MyResource

PUT - Update MyResource

 

to represent the individual resource, how could I represent updating just the Active flag

on this resource?

 

Maybe something like

 

/MyResources/{id}?Active={activeFlag}

PUT - Make the MyResource active or inactive

 

Is there a more RESTful way of representing this type of operation on a resource?

 

Thanks for your help.

 

Graham

Coordinator
May 18, 2011 at 8:21 AM
Nothing unrestful about the approach you suggested as long as it is PUT/POST.

A few alternate approaches

You could PUT to /MyResources/{id} a representation that sets the active flag within the body. This would mean sending the whole representation.

You could PATCH to /MyResources/{id} sending Active=true

You could PUT to /MyResources/{id}/active and send the value of 'true'. In this case active is a sub resource

All of the approaches are valid and RESTful. It is just a matter of preference. You can even support multiple if you want.

>
May 18, 2011 at 11:41 AM

Thanks Glenn for the reply.

Some interesting concepts you've raised here.

PATCH, this is a verb?

Sub resource. That to is a new concept to me ATM. I did notice that in one of your recent talks (at MIX 11 I think), you used what looked like sub resource itdentifiers to change the media type used on the response, i.e. you used something like /MyResource/{id}/png to return an image stream rather than XML.

Do you know of any good resources (book) for learning RESTful techniques?

Thank you

 

May 18, 2011 at 11:45 AM
On 18 May, 2011,at 12:41 PM, gravy wrote: > From: gravy > > Thanks Glenn for the reply. > > Some interesting concepts you've raised here. > > PATCH, this is a verb? http://tools.ietf.org/html/rfc5789 > > Sub resource. That to is a new concept to me ATM. I did notice that in one of your recent talks (at MIX 11 I think), you used what looked like sub resource itdentifiers to change the media type used on the response, i.e. you used something like /MyResource/{id}/png to return an image stream rather than XML. > > Do you know of any good resources (book) for learning RESTful techniques? Nothing against the books, but for me immersing myself in the dissertation and then reading rest-discuss worked best. It is not just about learning techniques - you have to go through the necessary brain-shift to see the light :-)  Jan > Thank you > > > > Read the full discussion online. > > To add a post to this discussion, reply to this email (wcf@discussions.codeplex.com) > > To start a new discussion for this project, email wcf@discussions.codeplex.com > > > You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com. > > Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


On 18 May, 2011,at 12:41 PM, gravy <notifications@codeplex.com> wrote:

From: gravy

Thanks Glenn for the reply.

Some interesting concepts you've raised here.

PATCH, this is a verb?


http://tools.ietf.org/html/rfc5789

Sub resource. That to is a new concept to me ATM. I did notice that in one of your recent talks (at MIX 11 I think), you used what looked like sub resource itdentifiers to change the media type used on the response, i.e. you used something like /MyResource/{id}/png to return an image stream rather than XML.

Do you know of any good resources (book) for learning RESTful techniques?


Nothing against the books, but for me immersing myself in the dissertation and then reading rest-discuss worked best.

It is not just about learning techniques - you have to go through the necessary brain-shift to see the light :-)

Jan



Thank you

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

--Boundary_(ID_D5R4lQqiWApROTYnnibslA)--