micro-analytics / micro-analytics-cli

Public analytics as a Node.js microservice. No sysadmin experience required! 📈
MIT License
734 stars 39 forks source link

Should a GET really change the value by default? #25

Closed tscharke closed 7 years ago

tscharke commented 7 years ago

At first I wanna say THANK YOU for this service and for your work. I'playing around with the service in the moment and it works totally fine 👍

I understand that this service provide a small (REST)-API (GET and POST). And all service i've seen before (Twitter, Facebook, Netflix, aso. ) never changing a value by sending a GET. Because a GET response all information and nothing more. If I wanna change values I have to send a request via POST or PUT. In the documentation you mention, that there is the query parameter "inc" to change this behavior. For me it was totally clear that a GET never change values/data by default and so lets implement that a GET only response information and POSTs and PUTs changing values. ;-)

What is your opinion about this? I would take care this task :-)

mxstbr commented 7 years ago

The nice thing about this behaviour is that displaying a public visit counter (which I built this initially for) is really easy:

fetch('myservice.com/page/2')
  .then(res => { console.log(`This page has ${res.views} views!`) })

This will both increment and return the views, making it super easy to do build things. I like that!

tscharke commented 7 years ago

Of course, this looks super simply - cool 😎 In my case you need two thinks (a PUT and after this a GET) to displaying a public visit counter. Mhh, no more arguments to do it REST-liker

tscharke commented 7 years ago

Wait...I saw your idea and get the picture.

The question is: Should this micro-service be a a good REST-service? In this case I love clear interfaces (or HTTP-methods like GET and PUT/POST) to understand the meaning directly. Or should this be a REST like -service to help to implement your use cases quick and easy?

mxstbr commented 7 years ago

Or should this be a REST like -service to help to implement your use cases quick and easy?

This is exactly it. I don't particularly care about adhering to REST for the sake of adhering to REST. Why do that if it ends up being less nice to use? ¯\_(ツ)_/¯

You could say it might be harder to understand, but as long as the documentation is clear on how it works (which I think it is since you immediately understood it!), this should be fine.

Closing, thanks for kicking off this discussion!