Welcome to the Linux Foundation Forum!

REST API implementation best practive

In the training, the author specify:
"Typically a service would either use POST or PUT for both creation and updates, or sometimes less-advisedly, POST for creation and PUT for updates. However, for understanding purposes, we'll implement PUT for updating and creating entries as well."

I am very surprised, I thought it was the contrary.
I have done some research to find the answer my myself but I found what I've already new.
POST for create and PUT for update seems to be the way to go.
What did I miss? Could you help me to understand?

Best Regards

Frédéric

Comments

  • xdxmxc
    xdxmxc Posts: 157

    my wording here isn't very clear but here's the breakdown:

    • POST for create and PUT for updates is the correct RESTful approach
    • using POST for both has pragmatic advantages that outweigh purity of approach (PUT generally has more compat/integration hurdles and the route name is generally enough to know what's happening
    • a lot of orgs generally have RESTful projects that use POST for both, others use POST/PUT and others have a mix
    • using PUT for both isn't really that sensible, but one of the reasons the example uses it for both is to explore PUT more (since POST is covered very well, everywhere) - because it very much depends on many different things as to what the best approach is for any given scenario (obv eg, working in a pure-RESTful impl context)

    thanks for bringing this up, I'll think about how to put it better without overloading the text

Categories

Upcoming Training