Tool for testing REST APIs Function
- python >= 3.6
- python-dev >= 3.6
- pip3.6
Run as root
apt update
apt install gcc git python3.7-minimal python3.7-dev python3-pip -y
python3.7 -m pip install --upgrade pip
Note that if you execute the last command without
sudo
,pip3.7
is installed in directory/home/{username}/.local/bin
which might not be in thePATH
variable, depending on the distribution you are running. Add the directory to thePATH
variable in order to be able to use it.
Run as root
yum update -y
yum install -y epel-release && yum update -y
yum install -y gcc git python3 python3-devel python3-pip
pip3.7 install dummyrest
git clone https://github.com/medianetlab/dummyrest.git
cd dummyrest
sudo pip3.7 install .
Note that if you execute the last command without
sudo
,dummyrest
script is installed in directory/home/{username}/.local/bin
which might not be in thePATH
variable, depending on the distribution you are running. Add the directory to thePATH
variable in order to be able to use it.
A new command has been installed. which starts the dummyrest application:
dummyrest
Add the &
at the end to run at the background
The dummyrest application is listening by default on port 8000. To check that the application has started run a curl request curl http://<IP>:8000/dummy
. You should get a 200 response with the message "Dummy REST API"
. By default the application writes a log file at the home directory of the user that started the application.
A sample database to store the resources of the example REST API is supported by the application. You can set it to use an external database by setting the DB_URL
environmental variable to the external databse URL before you start the application.
If no external database url is given, the application will use a local SQLITE3 database. You can set the path for the local db file by setting the SQLITE_DB_PATH
environmental variable before you start the application. If this variable is not set, by default the application will create the databse file on the home directory of the user that started the application, under the name dummyrest.db
.
To create a systemd service that will run the dummyrest application download the Github repository and run the script:
sudo ./systemd/create_service
Run systemctl status dummyrest
to check if the service has started successfully. The logs are stored in /var/run/dummyrest/logs/dummyrest.log
Run as root
apt install -y nginx
systemctl start nginx
systemctl enable nginx
systemctl status nginx
Run as root
Set up the yum repository for RHEL or CentOS by creating the file nginx.repo: vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
Install nginx:
yum update -y
yum install -y nginx
systemctl start nginx
systemctl enable nginx
systemctl status nginx
If the SELINUX is enabled, then it must be allowed to serve http
semanage permissive -a httpd_t
systemctl reload nginx
Remove any default file in /etc/nginx/conf.d/
or /etc/nginx/sites-enabled/
directories and create the /etc/nginx/conf.d/dummyrest.conf
file:
server {
listen 80 default_server;
server_name _;
location / {
include uwsgi_params;
uwsgi_pass unix:/var/www/html/dummyrest/socket.sock;
}
error_page 404 /404.html;
location /404.html {
root /usr/share/nginx/html;
}
}
Reload the nginx service: sudo systemctl reload nginx
Create the folder where the socket file will be saved:
sudo mkdir -p /var/www/html/dummyrest/
sudo chown -R ${USER}:${USER} /var/www/html/dummyrest
Run the dummyrest-nginx
script to start serving the dummyrest application on port 80
To make create a systemd service using the nginx as webserver, configure the nginx as described above and run the script:
./nginx/systemd/create_service.sh
API | Method | Data | Description |
---|---|---|---|
/dummy | GET | - | Get a list of all the items in the dummy resource |
/dummy | POST | JSON | Add a new item to the dummy resource |
/dummy/{id} | GET | - | Get the item with id=id from the dummy resource |
/dummy/{id} | POST | JSON | Create an item with id=id from the dummy resource |
/dummy/{id} | PUT | JSON | Update or create the item with id=id from the dummy resource |
/dummy/{id} | DELETE | - | Delete the item with id=id from the dummy resource |
API | Method | Data | Description |
---|---|---|---|
/books | GET | - | Get a list of all the books in the database |
/books | POST | JSON | Add a new book in the database |
/book/{title} | GET | - | Get the book with title=title from the database |
/book/{title} | POST | JSON | Add a new book with title=title in the database |
/book/{title} | PUT | JSON | Update or create the book with title=title in the database |
/book/{title} | DELETE | - | Delete the book with title=title from the database |
API | Method | Data | Description |
---|---|---|---|
/authors | GET | - | Get a list of all the authors in the database |
/authors | POST | JSON | Add a new author in the database |
/author/{name} | GET | - | Get the author with name=name from the database |
/author/{name} | POST | JSON | Add a new author with name=name in the database |
/author/{name} | PUT | JSON | Update or create the author with name=name in the database |
/author/{name} | DELETE | - | Delete the author with name=name from the database |