Dummy REST API
Tool for testing REST APIs Function
1. Requirements
- python >= 3.6
- python-dev >= 3.6
- pip3.6
1.1 Install python3.7 and pip3.7 on Debian system:
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.7is installed in directory/home/{username}/.local/binwhich might not be in thePATHvariable, depending on the distribution you are running. Add the directory to thePATHvariable in order to be able to use it.
1.2 Install python3.7 and pip3.7 on CentOS > 7 system:
Run as root
yum update -y
yum install -y epel-release && yum update -y
yum install -y gcc git python3 python3-devel python3-pip
2. Installation
2.1 PyPI
pip3.7 install dummyrest
2.2 Github
git clone https://github.com/medianetlab/dummyrest.git
cd dummyrest
sudo pip3.7 install .
Note that if you execute the last command without
sudo,dummyrestscript is installed in directory/home/{username}/.local/binwhich might not be in thePATHvariable, depending on the distribution you are running. Add the directory to thePATHvariable in order to be able to use it.
3. Usage
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.
4. Database
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.
5. Create a systemd service
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
6. Use dummyrest with NGINX
6.1 Install NGINX
6.1.1 Debian
Run as root
apt install -y nginx
systemctl start nginx
systemctl enable nginx
systemctl status nginx
6.1.2 CentOS
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
6.2. Configure NNGINX
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
6.3 Create systemd service with nginx
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
7. Available APIs
7.1 Dummy
| 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 |
7.2 Books
| 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 |
7.3 Authors
| 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 |
Metadata
Release files for dummyrest 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dummyrest-0.1.1.tar.gz | 8.5 kB | Without provenance | Details for dummyrest-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dummyrest-0.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for dummyrest-0.1.1-py2.py3-none-any.whl |
Total release size: 18.5 kB
Release files / dummyrest-0.1.1.tar.gz
| Download URL | dummyrest-0.1.1.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bee41c706948cdc4303203f050f973da55731f3b0fc3bac80a681af30b75ddec
|
|
BLAKE2b-256 checksum How to use checksums |
fd811b66462944ca2fe1627692e05efaed2c3bbbe9c79ce7d684839d3b858c3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
|
Release files / dummyrest-0.1.1-py2.py3-none-any.whl
| Download URL | dummyrest-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
68c1f8a5c6d7025a744389bf367292fbcc6e435f15fe77390b33cc8b43e01e51
|
|
BLAKE2b-256 checksum How to use checksums |
736be190b9af6ad34101aeddb55e899e1d26a4c81d4ac82a418bf1a6d5597bfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
|
Security for dummyrest 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.