ppi
ppi

Reputation: 86

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?

Upvotes: 0

Views: 861

Answers (2)

Maurice Mohlek
Maurice Mohlek

Reputation: 36

A PATCH contains an ID.
So you could check if ID != null and throw an error instead.
On this way you don't need to check the database.
This solution assumes that you don't generate id's on the client.

Upvotes: 0

masterspambot
masterspambot

Reputation: 516

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

Upvotes: 0

Related Questions