Search code examples
javahttprequestspring-rest

Which REST method to use if only sending path variable and key-value pair in header to trigger business logic?


I'm working on a web-game for training purposes. In this project I'm using Spring-Boot and REST endpoints to execute CRUD operations and trigger business logic methods. One endpoint of mine looks like this:

@PatchMapping("companies/{companyId}/upgrade-star-value")
    @ResponseBody
    public String upgradeStarValue(@PathVariable int companyId, @RequestHeader(name = "playerId") int playerId)
            throws GameLogicException {
        return companyBusinessLogicService.upgradeStarValue(playerId, companyId);
    }

The purpose of this endpoint is to trigger a method that validates the amount of specific resources of the player with the passed playerId and then reduces them and upgrades the star value of the company with the passed companyId. So everything is done without a request body.

Know I was wondering which REST method I should use to accomplish that. Should I use POST or PATCH or is there another method for the case that no request body but path variable and request header is sent? Is there a best practice to deal with such a case?

I tried to look up other posts, but it's hard for me to briefly express my problem in a google search, so the results don't apply to my problem. Therefore I am happy about hints to other posts.


Solution

  • You have mentioned that your operation is not idempotent. In such case POST will suit your needs and will be more or less RESTful.