0

I've been trying to get the HTTP verbs right lately, however I have a doubt regarding using PUT, PATCH or even POST for the following scenario.

The front end part is sending the following JSON data:

{
    name: "Spanish-01",
    code: "ESP01",
    students: [{
        IdStudent: 1,
        name:  "Peter Parker"
    },
    {
        IdStudent: 2
        name:  "Ben Reilly",
        dirtyRemove: true
    }]
}

The back end code will update the Class record (e.g name and code). However, it will also delete the students with flag dirtyRemove, and those live in another table called Student.

So what's the rule here? Since PUT and PATCH according to w3.org here is for updating an existing resource. In this case the back end is both updating and deleting at the same time?

Should I use PUT or PATCH or neither?

NOTE: Don't mind about the FE part, I minimized the scope in order to get a more straightforward example

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
Luis Deras
  • 1,239
  • 2
  • 19
  • 48

1 Answers1

1

How your resources are implemented internally using tables is an implementation detail. It doesn't matter.

That said, your example payload doesn't fit PUT (to remove a student, you would omit it). It might fit PATCH, if you properly label the payload with a content type describing what semantics you expect.

Nit: the HTTP spec is not a W3 document, and the version you're looking at is outdated.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98