ajax - Should I use REST style URLs with PUT and DELETE in my web app? -
i have spa (single page application) uses ajax extensively getting , saving data , server. in 1 case allow admin view/add/edit/delete users. current urls area looked like:
(get) /users?userid=1 // user id of 1 (post) /users?userid=1&firstname=jim // update first name of user id 1 (post) /users?firstname=bob // create new use first name bob (post) /users?userid=1&delete=true // delete user id of 1
having spent time working on restful api in related project, i'm wondering if it's preferred use http types (get, post, put, delete) in web app well. also, better use path parameter user id instead of query parameter? these urls (rewrite of ones above) better option in long run:
(get) /users/1 // user id of 1 (put) /users/1?firstname=jim // update first name of user id 1 (post) /users?firstname=bob // create new use first name bob (delete) /users/1 // delete user id of 1
in theory yes should. should restful possible means using http semantics fullest. reality bit more murky, several older browsers, don't need name names, don't support get
, post
. current recommendation until browsers go out of support, or until drop support browsers, have backup methods same thing on post
, parameter or segment in url.
Comments
Post a Comment