margyle / decaf

Decaf: Does Every Coffee Action, Friend
26 stars 10 forks source link

Change barcodeScanner and relayControl to be POST requests #22

Closed levi closed 5 years ago

levi commented 5 years ago

Resolves #2

jjok commented 5 years ago

It definitely shouldn't be using GET for these requests. This will be a breaking change for any client(s) that (presumably?) exist though. I don't know if that matters at this stage.

margyle commented 5 years ago

Just finally getting a chance to review this. Will merge tonight or tomo morning depending on how much I get done this eve. Apologies for the delay and thanks again!

margyle commented 5 years ago

@jjok Taking the client aspect out of it for now, are there benefits to using get over post for these two examples? Or vice-versa? I think the goal right now should be to make Decaf work in the most obvious manner for the most amount of people according to best practices. I'll admit that with Flask specifically, my instincts may not naturally line up with what is best for most, so I'm very interested in hearing your and @levi's perspectives.

jjok commented 5 years ago

The idea (with HTTP in general) is that a GET request doesn't make any changes to the state of the server. You should be able to make the same request several times and get the same response (idempotent?). To make changes to the state of the server (or to operate some peripheral in the case) you have to make a request like POST, PUT, DELETE.

jjok commented 5 years ago

Something I have been thinking, which I may open a separate issue about, is that I'm not really sure that brewing coffee very easily fits into the REST model of APIs. REST usually good if you're creating, updating and deleting resources. I think maybe an RPC-style API make work better, where each endpoint is the name of a function that can be called startGrinder(), brewCoffee() etc and the body of the request is the parameters to those functions. I'd be interested in hearing people's opinions. Let me know what you think.

margyle commented 5 years ago

The idea (with HTTP in general) is that a GET request doesn't make any changes to the state of the server. You should be able to make the same request several times and get the same response (idempotent?). To make changes to the state of the server (or to operate some peripheral in the case) you have to make a request like POST, PUT, DELETE.

Thanks @jjok, this makes sense.