2.5 KiB
To edit data in the database we wanna use PUT request.
What is a put request?
To edit data in the database we wanna use PUT request. A PUT request is used to update an existing resource. If the resource does not exist, it will create a new one. The PUT request requires the client to send the entire updated resource, not just the changes. This means that the client must send all the data, even if only one field has changed.
A put request is a json its for example looks like this:
{
"NodeID": 1,
"Location": "testlocation",
"Name": "testname",
}
How to use a put request
We have been trying to use a PUT request with flask. But that didn't work because the reverse proxy would reform the request to a GET request. So we tried to let apache 2 run it with wsgi.
What is wsgi?
WSGI stands for Web Server Gateway Interface. It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request. WSGI is a Python standard, and it is implemented by most Python web frameworks.
We couldnt get it to work even though we worked trough all the errors apache 2 gave us.
We first had some paths misconfigured. Then we had Forbidden error because we didn't give permission for apache2 to use that path.
And now we ended on not found and we verified that all configuration is in the correct syntrax with apachectl configtest
How to use wsgi
To use wsgi you need to install mod_wsgi with the following command:
sudo apt-get install libapache2-mod-wsgi
Then you need to enable the module with the following command:
sudo a2enmod wsgi
Then you need to create a wsgi file in the same directory as your python file. The wsgi file should look like this:
import sys
sys.path.insert(0, '/home/pi/webapp')
from mainflask import app as application
Then you need to configure your apache2 configuration file to use the wsgi file. The configuration file should look like this:
<VirtualHost *:80>
DocumentRoot /home/pi/www/html/
WSGIDaemonProcess webapp python-path=/home/pi/webapp
WSGIScriptAlias /flask /home/pi/webapp/main.wsgi
<Directory /home/pi/webapp>
WSGIProcessGroup webapp
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
# Logging
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then you need to restart apache2 with the following command:
sudo systemctl restart apache2