Skip to content

Commit

Permalink
Revert "Replace PUT with PATCH"
Browse files Browse the repository at this point in the history
This reverts commit c8581fb.

Web::Machine doesn't support PATCH yet, and it seems like no other
implementation in another language does either.

webmachine/webmachine-ruby#109
for-GET/http-decision-diagram#35
  • Loading branch information
sartak committed Dec 13, 2016
1 parent c8581fb commit 2a5b9db
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ USAGE
Currently provided endpoints under /REST/2.0/ are:

GET /ticket/:id
PATCH /ticket/:id <JSON body>
PUT /ticket/:id <JSON body>
DELETE /ticket/:id
Sets ticket status to "deleted".

GET /queue/:id
PATCH /queue/:id <JSON body>
PUT /queue/:id <JSON body>
DELETE /queue/:id
Disables the queue.

GET /user/:id
PATCH /user/:id <JSON body>
PUT /user/:id <JSON body>
DELETE /user/:id
Disables the user.

Expand All @@ -41,7 +41,7 @@ USAGE
When a GET request is made, each endpoint returns a JSON representation
of the specified resource, or a 404 if not found.

When a PATCH request is made, the request body should be a modified copy
When a PUT request is made, the request body should be a modified copy
(or partial copy) of the JSON representation of the specified resource,
and the record will be updated.

Expand Down
8 changes: 4 additions & 4 deletions lib/RT/Extension/REST2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ Add this line:
Currently provided endpoints under C</REST/2.0/> are:
GET /ticket/:id
PATCH /ticket/:id <JSON body>
PUT /ticket/:id <JSON body>
DELETE /ticket/:id
Sets ticket status to "deleted".
GET /queue/:id
PATCH /queue/:id <JSON body>
PUT /queue/:id <JSON body>
DELETE /queue/:id
Disables the queue.
GET /user/:id
PATCH /user/:id <JSON body>
PUT /user/:id <JSON body>
DELETE /user/:id
Disables the user.
Expand All @@ -69,7 +69,7 @@ For queues and users, C<:id> may be the numeric id or the unique name.
When a GET request is made, each endpoint returns a JSON representation of the
specified resource, or a 404 if not found.
When a PATCH request is made, the request body should be a modified copy (or
When a PUT request is made, the request body should be a modified copy (or
partial copy) of the JSON representation of the specified resource, and the
record will be updated.
Expand Down
11 changes: 3 additions & 8 deletions lib/RT/Extension/REST2/Resource/Record.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,12 @@ sub last_modified {
return create_date($updated);
}

sub known_methods {
my $self = shift;
return [@{$self->SUPER::known_methods(@_)}, 'PATCH'];
}

sub allowed_methods {
my $self = shift;
my @ok;
push @ok, 'GET', 'HEAD' if $self->DOES("RT::Extension::REST2::Resource::Record::Readable");
push @ok, 'DELETE' if $self->DOES("RT::Extension::REST2::Resource::Record::Deletable");
push @ok, 'PATCH', 'POST' if $self->DOES("RT::Extension::REST2::Resource::Record::Writable");
push @ok, 'GET', 'HEAD' if $self->DOES("RT::Extension::REST2::Resource::Record::Readable");
push @ok, 'DELETE' if $self->DOES("RT::Extension::REST2::Resource::Record::Deletable");
push @ok, 'PUT', 'POST' if $self->DOES("RT::Extension::REST2::Resource::Record::Writable");
return \@ok;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/RT/Extension/REST2/Resource/Record/Writable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ sub from_json {
);

my $method = $self->request->method;
return $method eq 'PATCH' ? $self->update_resource($data) :
$method eq 'POST' ? $self->create_resource($data) :
\501 ;
return $method eq 'PUT' ? $self->update_resource($data) :
$method eq 'POST' ? $self->create_resource($data) :
\501 ;
}

sub update_resource {
Expand Down Expand Up @@ -69,7 +69,7 @@ sub create_resource {
if ($self->resource_exists) {
return error_as_json(
$self->response,
\409, "Resource already exists; use PATCH to update");
\409, "Resource already exists; use PUT to update");
}

my ($ok, $msg) = $self->create_record($data);
Expand Down
2 changes: 1 addition & 1 deletion lib/RT/Extension/REST2/Resource/Role/RequestBodyIsJSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ role {
return $malformed if $malformed;

my $request = $self->request;
return 0 unless $request->method =~ /^(PUT|POST|PATCH)$/;
return 0 unless $request->method =~ /^(PUT|POST)$/;

my $json = eval {
JSON::from_json($request->content)
Expand Down
8 changes: 0 additions & 8 deletions t/lib/RT/Extension/REST2/Test.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ sub mech { RT::Extension::REST2::Test::Mechanize->new }

return $json->decode($res->content);
}

# modeled off of LWP::UserAgent::put
sub patch {
require HTTP::Request::Common;
my($self, @parameters) = @_;
my @suff = $self->_process_colonic_headers(\@parameters, (ref($parameters[1]) ? 2 : 1));
return $self->request( HTTP::Request::Common::_simple_req( 'PATCH', @parameters ), @suff );
}
}

1;

0 comments on commit 2a5b9db

Please sign in to comment.