Samuel García
Samuel García

Reputation: 2225

Using empty PUT on a REST service

I'm wondering if it is correct to use a PUT request with an empty body.

The service just clones an existing object and persists it with a new identifier, like

PUT /object/clone/{objectId}

Is this correct?

Upvotes: 3

Views: 916

Answers (3)

David Barker
David Barker

Reputation: 14620

If you are following a true RESTful approach using PUT/PATCH makes a little sense though PUT/PATCH in some schools of thought is used predominantly to update/edit an existing resource rather than create. If following this thinking a POST request would make more sense.

If I was posed with this dilemma I'd say a POST request would be more viable for creation (how it is created is down to implementation not the language used to request it's construction).

Upvotes: 1

Marcin Szymczak
Marcin Szymczak

Reputation: 11453

Since you are creating new element that is legitimate solution. Even better would be to use POST.

Upvotes: 1

Artem Moskalev
Artem Moskalev

Reputation: 5828

According to this (part about REST-methods):

https://docs.oracle.com/cd/E38689_01/pt853pbr0/eng/pt/tibr/concept_UnderstandingRESTServiceOperations.html

it is better to use the POST-request for this, as long as you are creating a new resource using the existing URL.

Upvotes: 3

Related Questions