Jump to content

REST API responses when deleting records


NotionCommotion

Recommended Posts

I have the following tables:

  • department
    • id
  • course
    • id
    • department_id CASCADE DELETE
  • student
    • id
  • student_courses
    • course_id CASCADE DELETE
    • student_id CASCADE DELETE

I also have the following REST API endpoints:

  • DELETE department/123 (deletes targeted department and associated courses as well as the list of students in the course)
  • DELETE course/321 (deletes targeted course as well as the list of students in the course)
  • DELETE student/111 (deletes targeted student as well as the list of students in the course)

The user should be informed before deleting a given record if that record will affect other tables.  For instance, if deleting a department which has some courses or deleting a student which belows to a course.

One option is to respond to DELETE department/123 with 400 {recordUsed: {courses:[bla, bla], student_courses:[bla, bla]}} if used.  For this option, the client would then prompt the user of the implications and if desired repeat the request but include a "force" parameter of TRUE in the request which will delete the record regardless of being used.

Another option is to add some new endpoints which will return the resources which are associated with the to be deleted entity.  If empty, a DELETE request would automatically be made and if not empty the user will first be prompted whether the DELETE request should be made and the server would delete the record(s) regardless of being used.

  • GET department/utilized/123
  • GET course/utilized/321
  • GET student/utilized/111

Any thoughts on which approach should be used?  Or maybe some other strategy?  Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.