java - Whats the best way to design DELETE for a restful resource -
trying find out way design delete.
trying explain using example:
i have resource employee. employee has following fields
employee{ string firstname string lastname string emailid string manageremployeeid string employeeid } i want ability delete employee using of fields e.g. firstname , lastname , employeeid , or manageremployeeid
how should resource paths ideally
option1: option ? yes ? no ? why ?
/employee/id/{employeeid} /employee/firstname/{firstname} /employee/lastname/{lastname} /employee/managerid/{managerid} option2:
use of query params
/employee?id=100 ( delete employee id 100) /employee?firstname=tom&lastname=winn (to delete employee named tom winn) /employee?manageremployeeid=400 (delete employees having manager id 400) option 1 looks rpc-ish me
i second option find error prone since fields have specified.
in 2nd option don't idea of having param named firstname , mapping firstname field in java class employee. used paradigm in industry ?
further backend application xml , written in java( use of loose field names looks un-java me)
i understand being followed in industry ( typed java+xml based rest systems built in jersey , resteasy or spring )
my vote go (a slight alteration of) option 1.
delete /employees/{employeeid} there's no need specify /id, can't imagine there's ever going confusion (unless have employee named bizarre uuid...). leads me why i'd others bad idea:
there should ever one employee id, there no room ambiguity. there many same firstname, lastname (and combinations may not unique).
if put /id in string, implies (to me @ least) there may other way uniquely refer resource (e.g. /firstname or /lastname suggest); omitting leaves clear that's only way support referencing specific employee, , if want find 1 specific firstname , lastname, should retrieved get /employees?firstname=tom&lastname=winn type request.
query parameters in delete sound risky me, , more whatever calling service should in charge of. if want delete employees managerid=400, makes more sense get resources: get /employees?managerid=400, , issue delete on returned employees.
Comments
Post a Comment