Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

Is it ok to create entity in GET REST controller method with name getOrCreateIfNotExist?

$
0
0

So, I have some task, I have to create endpoint that should getOrCreateIfNotExist. But I`m not sure, is it ok practice to create some entity in the GET request. Or I should to do another call to the POST method to create new entity. Maybe like this:

    @GetMapping("")    public List<SOMEOBJECT> getOrCreateIfNotExist(SOME DATA){        return questionService.getOrCreateIfNotExist(SOME DATA);    }

OR I should write like this:

    @GetMapping("")    public List<SOMEOBJECT> getOrCreateIfNotExist(SOME DATA){          if(questionService.getOrCreateIfNotExist(SOME DATA) == null){             create(SOME DATA)          }    }    @PostMapping("")    public List<SOMEOBJECT> create(SOME DATA){        return questionService.create(SOME DATA);    }

I want to know what is best practice and is it good to do 2 things in one request?


Viewing all articles
Browse latest Browse all 3630

Trending Articles