Run a HTTP REST server that serves JSON* content from files.
* other file types work as well, the content-type
is determined by the file extension.
It's a couple of lines of Kotlin code, using Ktor and Clikt.
If you need a more advanced mock REST JSON server, then please have a look at JSON Server.
Provide REST path and file mapping 'routes' as arguments, e.g.:
--route "/api/products/=/data/allProducts.json"
--route "/api/customers/=/data/allCustomers.json"
etc.
A pre-build image can be found here: rlindooren/simple-rest-json-server:latest
# Update this to match your own set-up
DATA_DIR="$(pwd)/example-data/"
PORT=8080
docker run \
--rm \
--volume "${DATA_DIR}:/data/" \
-p "${PORT}:${PORT}" \
--env "PORT=${PORT}" \
rlindooren/simple-rest-json-server:latest \
--route "/api/products/=/data/allProducts.json" \
--route "/api/customers/=/data/allCustomers.json"
Then goto http://localhost:8080/.
./gradlew run --args="--route /api/products/=example-data/allProducts.json --route /api/customers/=example-data/allCustomers.json"
./gradlew installDist
docker build -t simple-rest-json-server .
# Update this to match your own set-up
DATA_DIR="$(pwd)/example-data/"
PORT=8080
docker run \
--rm \
--volume "${DATA_DIR}:/data/" \
-p "${PORT}:${PORT}" \
--env "PORT=${PORT}" \
simple-rest-json-server \
--route "/api/products/=/data/allProducts.json" \
--route "/api/customers/=/data/allCustomers.json"
When serving really large files you may have to extend the available memory(?). For example like so:
docker run \
--env "JAVA_OPTS=-Xmx2024M" \
--memory=2g \
...