Search code examples
javaspring-bootjson-apikatharsis

Katharsis Json Api restrict PATCH


I am using Katharsis library in my Spring Boot server to build automatically JSON-API interface.

Let's say I have an endpoint (resource) /resource, for which I would like to offer POST method (to create new resources) but restrict PATCH (to restrict resources updating). Meanwhile, the io.katharsis.repository.ResourceRepository offers only save() method, which applies to both POST and PATCH.

My only idea at the moment is to add another Filter to FilterChain that will disallow PATCHing the required endpoint.

Are there any better (i.e. shorter or more elegant) ways to achieve this?


Solution

  • To disable PATCH method you should follow the steps:

    1. Check if in Database exists object with ID provided in requested URL
    2. If object exists, throw UnsupportedOperationException