Skip to content

Instantly share code, notes, and snippets.

@gregturn
Created January 7, 2015 17:19
Show Gist options
  • Select an option

  • Save gregturn/403b5e34e2dce9de1d19 to your computer and use it in GitHub Desktop.

Select an option

Save gregturn/403b5e34e2dce9de1d19 to your computer and use it in GitHub Desktop.
cujo rest DELETE
rest({method: 'DELETE', path: item._links.gallery.href})
.done(function() {
findLinkedItem(item).remove();
$('#images ul').append(createItemRow(item));
});
@scothis

scothis commented Jan 7, 2015

Copy link
Copy Markdown

By default, if the request is completed and a response is received, the promise success handler will be invoked, network errors will trigger the error handler.

You can change this behavior based on the status code with the rest/interceptor/errorCode interceptor, by default >=400 are treated as errors, but you can configure it.

As an aside, it looks like your trying to perform an operation on a related resource, if the 'item' was returned with HAL, you can instead do something like:

item.clientFor('gallery')({ method: 'delete' });

Using clientFor simply created a client for the href defined by the relationship. You can then invoke the client like any other. Templated hrefs will be expanded as well.

@gregturn

gregturn commented Jan 7, 2015

Copy link
Copy Markdown
Author

Thanks. For some reason, Spring Data REST stopped handling this delete operation, but I didn't realize it because the follow function, which moved the item in the DOM happened anyway. I'll try it out.

@gregturn

gregturn commented Jan 7, 2015

Copy link
Copy Markdown
Author

Ahh. Nice! Well, taken that, I think I found something perfect for my situation:

        item.clientFor('gallery')({method: 'DELETE'})
            .done(function(response) {
                if (response.status.code >= 200 && response.status.code < 300) {
                    findLinkedItem(item).remove();
                    $('#images ul').append(createItemRow(item));
                }
            });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment