GithubHelp home page GithubHelp logo

Comments (5)

galadril avatar galadril commented on August 28, 2024

So the correct implementation of an api should be:

POST > full json payloads (adds an item to the list).. (!not updating data!)
PUT > full json payload, updates items (!not adding new data!)
PATCH > partial json payload, updates items (!not adding new data!)
DELETE > deletes an item from the api

more info here:
https://jsonplaceholder.typicode.com/

from wlanthermo_esp32_software.

sochs avatar sochs commented on August 28, 2024

Thanks for your idea. But, what should the benefit be? The settings are not edited constantly and the traffic is already very low. In addition, POST is universal.

from wlanthermo_esp32_software.

galadril avatar galadril commented on August 28, 2024

"what should the benefit be?"
When you build an api, your building for the future benefits. Other developers that are going to consume your api and work with your data. You can't know whats needed in the future or not, so thats why there are standard definitions for building api's.

For example, I'm now looking into integrating this api into Domoticz, and I found that to set the pitmaster mode, the documentation tells me to upload the full json object, but I dont want to retrieve the latest json, just to update one value (pitmaster mode).

Also if you have the standard protocols in place, i would never look at POST for updating values.. I would always use PUT or PATCH to update full or partial. Developers are always quick, and always take too few time in reading documentation. So building stuff that's standard eases the use and speed of development.

I'm actually most of the times on the consumer side of an api, and I know that using correct api principles are going to be a benefit for the long run.

from wlanthermo_esp32_software.

galadril avatar galadril commented on August 28, 2024

Im not complaining btw, its just a though of me on how to improve on the api setup

from wlanthermo_esp32_software.

sochs avatar sochs commented on August 28, 2024

"Im not complaining btw, its just a though of me on how to improve on the api setup"
Don't worry, I just wanted to know the background.

"For example, I'm now looking into integrating this api into Domoticz, and I found that to set the pitmaster mode, the documentation tells me to upload the full json object, but I dont want to retrieve the latest json, just to update one value (pitmaster mode)."
There's a point behind it: it is not intended that single pitmaster values are changed. The Pitmaster is a unit and is only changed in one piece. PATCH would not be available here anyway, only PUT (instead of POST, with same JSON body).
Similar to the channel settings: a channel setting is always transferred at least with the channel number. This would leave only PUT with the transfer of a complete embedded channel object in order to remain in the API standard.
With SYSTEM or IOT parameters, PATCH would be possible.

"and I know that using correct api principles are going to be a benefit for the long run."
I basically agree with you, so thanks very much for the hint. Adding PUT/PATCH next to POST as request method wouldn't be the problem, but it would not change the current internal processing of requests. They are provided as specified in the documentation. This would also be the case with PUT/PATCH.

from wlanthermo_esp32_software.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.