Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating a key field in a RESTful web service

Ron McLeod
Posts: 976
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a subscriber registry with a RESTful web service interface to be used by external applications. Subscribers are uniquely identified by their IMSI.

What I am trying to figure-out is if I want to allow the IMSI to be changed, what would be the best method for the request, and what would be a proper response.

My current thinking is:
   - POST is not correct since a new resource is not be created
   - PUT is not correct since an entire resource is not being replaced
   - PATCH is correct since less than the entire resource is being updated

   - include a Location header is in the response which identifies the new location for the subscriber resource
   - use 201 status code to indicate success since clients may already understand that a new location will be provided with a 201

PATCH /hss/sub/imsi/123456789012345

201 Updated
Location: /hss/sub/imsi/123456789098765

Does this seem like the good approach? Any comments or suggestions?
Simon Roberts
Ranch Hand
Posts: 170
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that from a philosophical perspective, if you are creating a new primary key, you're creating a new record. That's POST. The problem is, you're really concurrently adding a new one and deleting the old. That's a PATCH. But in practice, if you really must do this (which I will admit seems to me, from the outside to be little short of sick and wrong! ) I think the clearest parallel is with updating, and that's a PUT.

Sorry, that probably doesn't help, but it might trigger more opinions!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic