a-know / Pixela

A service for generating GitHub-like graphs. Record and Track your habits or effort. All by API.
https://pixe.la
402 stars 26 forks source link

POST vs PUT pixel #32

Open Dennis-Dang opened 1 year ago

Dennis-Dang commented 1 year ago

Hi, I'm new to programming and just got started working on a fun project with APIs with python. I am not totally new to how APIs work, but know enough.

I am having trouble distinguishing the behavior of these two methods. I've seen tutorial videos made in the past where the POST method will not work if there is already an existing Pixel present on the same date. But oddly enough, that's now allowed. How is this different from modifying my Pixel with the PUT method to update it?

Should the PUT method be strictly only be used to modify Pixels, and the POST method be strictly used to create new pixels as worded in the documentation?

TLDR; how is it that I am able to overwrite/modify Pixels with the POST method? Is this an intended feature or a minor bug that should be addressed?

a-know commented 1 year ago

@Dennis-Dang Hi, thank you for asking. Good question.

Originally, the POST method could not update an existing pixel and the PUT method could not register a new pixel. It was close to what it should have been for REST, but yes, it was very inconvenient.

This led to the current specifications that we have to this day. If Pixela were to make a major upgrade, this would be a smarter specification.

However, there are still minor differences between the two at this time. That is, the PUT method can update partial properties (docs). If that sounds attractive to you, then by all means use the PUT method. 😉