This a simple Node.js based mock server to test the bookingAPI. The mock implementation is intended for fast protoyping and to get the API right (Getting APIs right is hard).
To get the API right, a small web application is provided (we are drinking our own champagne).
Once the API is right, the API will be implemented of SBB's distribution system and provided by a simple to access API Management tool. Here is an example of how it might look like:
More to come...
The easiest way is to pull the docker image:
docker pull schlpbch/bookingapiThe latest docker image is always available at https://hub.docker.com/r/schlpbch/bookingapi/.
The easiest way is to run the docker image:
docker pull schlpbch/bookingapi
docker run -d -p 80:8080 --name bookingapi-mock schlpbch/bookingapior start with
node app.jsThe web app and the API are then running at http://localhost/
Using docker-compose a software defined firewall (see NGINX) is added in front of the mocked server and is linked to the mock server using a software defined network. This allows us to test authentication methods using JSON Web Tokens (JWT) later.
See docker-compose.yml for details.
To start simply use
docker-compose upThe server uses self signed certificates, they must be replaced with real ones for production!
First, Nodejs and npm which comes with it is needed. Then to install all the modules, simply run:
npm installThis will install the package defined in package.json file.
To run the App, do:
npm run devTo edit the API interactively, do:
swagger project editThe browser will then provide you with tab to edit the specification.
To run Swagger in mock mode, start with:
swagger project start -mTo run the tests:
swagger project testTo run the mock server, do:
swagger project startor more simple:
npm run devnpm run dev runs the the express app. It also creates a bundle for the
front-end part. This bundle includes source maps for debugging.
To run the app in production please run the following command
npm run prodwhich minifies the bundle and excludes source maps as we do not want to deliver our code in plain text.
To run the mock server as docker container, do:
docker build .
docker run -d -p 8080:8080 --name api-mock-srv <containerId>