Matelutex
Matelutex

Reputation: 2220

PUT VS PATCH for operation set template to default

I have to change one value (template) in my entity A:

class A {
private Template template
}

My endpoint looks like: /warehouse/company/{companyId}/template/default

with body:

class MyDto {
private Long templateId
}

What is the best solution for this operation? I want to change only one value in my entity: based on MyDto I have to fetch template from DB and set A.setTemplate(newTemplateFromDB).

The best option would be PATCH without RequestBody, but request body is necessary...

Upvotes: 0

Views: 33

Answers (1)

João Dias
João Dias

Reputation: 17510

You should definitely use PATCH because you are partially updating your resource (A) and not completely updating it. If you would update the complete resource by replacing your DB data with whatever you receive in the endpoint, then you should use PUT.

I just don't get why you say that the best option would be without the request body.

Upvotes: 1

Related Questions