1

To update the resource i have exposed following reset web api url -

http://server.com/api/v1/{companyid}/resources/{resourceid}

and request body contains the resource to be updated.

I have also exposed a seperate API to update a property of same resource. From business rule perspective this is special property and cannot be updated/retrieved along with normal resource api.

So using following url to expose separate api as below -

http://server.com/api/v1/{companyid}/resources/{resourceid}/property?propertyKey=propertyValue

this does not sound good. Is there better approach?

Prescott
  • 7,312
  • 5
  • 49
  • 70
Bhalchandra K
  • 2,631
  • 3
  • 31
  • 43
  • I think that's fine. you could also do `api/v1/{companyid}/resources/{resourceid}/{property}`. Since it's an update, I assume the body of your `put` or `post` has the value to update that property to – Prescott Aug 06 '14 at 06:58
  • In case of updating the resource body contains the resource model. In case of updating only the specific single property the value comes along with URL instead of body. – Bhalchandra K Aug 06 '14 at 07:01
  • 1
    If you want to include that property value in the URL, then I think you're doing fine. You could alternatively do something like `PUT api/v1/{companyid}/resources/{resourceid}/{property}/{propertyvalue}`. Again, I think you're fine – Prescott Aug 06 '14 at 07:03
  • Do NOT version URLs ... http://stackoverflow.com/questions/972226/how-to-version-rest-uris – David Brabant Aug 06 '14 at 07:05
  • @david-brabant, your right APIs are in beta release right now, with some debate over versioning approach internally. This will be the public facing apis in ecommerce domain. – Bhalchandra K Aug 06 '14 at 07:08

1 Answers1

3

Answer from the comments for others

PUT api/v1/{companyid}/resources/{resourceid}/{property} with the Body containing the value of the property is one way.

PUT api/v1/{companyid}/resources/{resourceid}/{property}/{propertyvalue} is another way if you want the value entirely in the URL.

Of course, http://server.com/api/v1/{companyid}/resources/{resourceid}/property?propertyKey=propertyValue is also probably fine.

As @David-Brabant mentioned don't version your API's in the URL

Community
  • 1
  • 1
Prescott
  • 7,312
  • 5
  • 49
  • 70