natiginfo / bookingAPI

A simple API to book tickets for public transport in Switzerland.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status dependencies Status

About

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...

Here you can find a initial functional road map.

Installing

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/.

Running the Mock Server

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/

Running the Mock Server with NGINX Firewall

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!

Live App and Documentation

The Web App is available at:

Thanks to SwaggerUI the up-to-date documentation is always available at:

and the latest JSON can be accessed at:

Developing 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 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>

ToDo

  • Integrate Swagger Middleware to easily pre-populate data
  • Get the API right
  • Expose journey planning as a route of its own
  • Setup API Management
  • Setup Security (JSON Web Token)
  • Products API
  • Cache-Control
  • SuperSaver Prices
  • Validity-Information for Prebookings (20 min offers 30 min prebookings)

Done

  • Clarify legalese
  • Align with FSM specification
  • Complete wiring Wep App with API
  • Translate API to English
  • Write a client to verify the usability of the API (APIs are UIs for developers).
  • Align with Fahrplan team
  • Align with Open Data (better Open API) team

About

A simple API to book tickets for public transport in Switzerland.

License:Apache License 2.0


Languages

Language:JavaScript 72.4%Language:HTML 24.2%Language:CSS 2.8%Language:Dockerfile 0.6%