This project is an example warehouse API that can be used for demos and proof of concepts. Please note this API was not built for high scalability.
-
Clone the warehouse-api-monolith repo:
git clone https://github.com/mkryshak/warehouse-api-monolith.git cd warehouse-api-monolith
-
Build the NGINX Unit base container image:
docker build --file ./nginx-unit/Dockerfile --tag <namespace>/nginx-unit:1.17 ./nginx-unit
-
Configure and initialize the warehouse database with pre-loaded data:
docker build --file ./mysql/Dockerfile --tag <namespace>/warehouse-api:database ./mysql
Notes:
The default username and password are configured as root/root. To specify a new username and password, modify the ./mysql/Dockerfile file accordingly:FROM mysql/mysql-server:5.7 ENV MYSQL_USER=<new_username> \ MYSQL_ROOT_PASSWORD=<new_password> COPY init /docker-entrypoint-initdb.d EXPOSE 3306 33060 CMD ["mysqld"]
Any changes to the default username and password require a similar change to the ./mysql/init/init_db.sql file:
GRANT ALL PRIVILEGES ON *.* TO '<new_username>'@'%' IDENTIFIED BY '<new_password>'; FLUSH PRIVILEGES;
And to the ./warehouse-api/www/config.json file:
{ "mysql": { "server": { "host": "warehouse-api-database", "port": "3306" }, "username": "<new_username>", "password": "<new_password>" } }
Data can be pre-loaded into the database at build time using the ./mysql/init/db-warehouse.sql file.
-
Update the ./warehouse-api/Dockerfile file to reflect the NGINX Unit container image name created in step one:
FROM <namespace>/nginx-unit:1.17
-
Build the warehouse-api application container image:
docker build --file ./warehouse-api/Dockerfile --tag <namespace>/warehouse-api:monolith ./warehouse-api
Notes:
-
The hostname of the database container used by the warehouse-api application is stored in the ./warehouse-api/www/config.json file. Modify as necessary.
-
The default SSL certificate uses the hostname "warehouse-api.nginx.net"
-
To use a custom SSL certificate and key, contatenate the certificate and key files together:
cat <certificate_file> <key_file> ./warehouse-api/tls/<hostname>
-
Update the ./warehouse-api/unit/conf.json file to reflect the newly concatenated certificate/key file name:
"listeners": { "*:80": { "pass": "applications/monolith" }, "*:443": { "pass": "applications/monolith", "tls": { "certificate": "<new_file_name>" } }
-
-
Bring up the containers:
docker-compose up -d
The warehouse-api application accepts both HTTP and HTTPS traffic on ports 80 and 443, respectively. The default URI prefix is /api/v1/warehouse
(this can be changed).
The following URIs will accept GET
requests to fetch product information:
/api/v1/warehouse/product
/api/v1/warehouse/prodcut/{sku}
/api/v1/warehouse/product/description/{sku}
/api/v1/warehouse/product/inventory/{sku}
/api/v1/warehouse/product/price/{sku}
/api/v1/warehouse/product/rating/{sku}
The following URIs will accept POST
requests to create products:
/api/v1/warehouse/product/{sku}
The following URIs will accept PATCH
requests to update specific information about a product:
/api/v1/warehouse/product/description/{sku}
/api/v1/warehouse/product/inventory/{sku}
/api/v1/warehouse/product/price/{sku}
/api/v1/warehouse/product/rating/{sku}
The following URIs will accept PUT
requests to update all information about a product:
/api/v1/warehouse/product/{sku}
The following URIs will accept DELETE
requests to delete products:
/api/v1/warehouse/product/{sku}
Notes:
{sku}
represents the SKU ID (integer) of a specific product- The request body for
POST
,PATCH
, andPUT
requests must contain the information about the product being created/updated. Use aGET
request from/api/v1/warehouse/product/{sku}
as a template and remove thecreated
andupdated
fields.
Data received from GET
requests can be filtered using the query string parameter fields
:
curl http://localhost/api/v1/warehouse/product?fields=name
Multiple fields can select using +
as a separator:
curl http://localhost/api/v1/warehouse/product?fields=name+quantity+retail
A special field selector called sku
can be used to return all SKU IDs:
curl http://localhost/api/v1/warehouse/product?fields=sku
Environment variables can used to set certain configuration parameters in the warehouse-api
application:
- BASE_URI - the default URI prefix for all incoming API requests (default:
/api/v1/warehouse
) - CFG_FILE - the full path of the JSON configuraton file used by the application (default:
/www/config.json
) - LOG_FILE - the full path of the application error log (default:
/var/log/error.log
) - MAP_FILE - the full path of the JSON map file (default:
/www/map.json
)
Warning!
The CFG_FILE
, LOG_FILE
and MAP_FILE
environment variables should not be modified unless you know what you're doing.