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/bookingapi
The 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/bookingapi
or start with
node app.js
The 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 up
The 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 install
This will install the package defined in package.json file.
To run the App, do:
npm run dev
To edit the API interactively, do:
swagger project edit
The browser will then provide you with tab to edit the specification.
To run Swagger in mock mode, start with:
swagger project start -m
To run the tests:
swagger project test
To run the mock server, do:
swagger project start
or more simple:
npm run dev
npm 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 prod
which 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>