- Thu Aug 02, 2018 4:14 am
There are many ways to access a url, they are called verbs or methods. They are used for reading data, changing data, deleting data or simply for asking if a url exists. What your browser does is submitting "GET /gpio/0" or "GET /gpio/1" and as the name says your app should handle this as a request which reads. Your app should never change any state following a GET request. That's what a POST or PUT request ist for.
Chrome sends some request to your app actually before you press Return. Either it's looking whether this URL exists or it tries to fetch the favicon in advance. But you can be sure Chrome will never send a POST or a PUT request on its own.
Actually it's very simple to implement it right:
* "GET /gpio" should return the current state
* "POST /gpio" with a new value or simply "POST /gpio/X" should change the current state. you have to redirect to "/gpio" afterwards to make it fail-proof.
And always remember: never ever change data using a request which reads data (GET). Have a look at https://en.wikipedia.org/wiki/Hypertext ... fe_methods
There are no tricks here