This repository contains a REST API for querying information about train compositions. It uses internally the digitraffic API available at https://rata.digitraffic.fi/ .
The app is deployed in heroku at https://intense-oasis-92112.herokuapp.com/api-docs/ .
Use npm install
to install the required dependencies.
Use node server
to start up the server.
The Main API is available as POST endpoint at http://localhost:3000/train-composition. Its required parameters are specified in JSON body, e.g.:
{
stationShortCode: SLO, // Specifies the station short code
trainNumber: 197,194 // Specifies the numbers of the trains to retrieve
}
More detailed REST API documentation is hosted by the node app itself using Swagger UI. When running locally, it is hosted at http://localhost:3000/api-docs/ .
To reach production quality, the following should still be done:
- Add automatic/unit tests
- Better error management (messages, error codes)
- Host the API using HTTPS instead of HTTP
- Limit the amount of operations done to digitraffic API. Now the implementation starts several composition queries in parallel which might end up returning errors or timeouting due to limits in the digitraffic API implementation.
- Add validation for the input parameters
- Support also GET operation
- Support for form parameters
- Clean up the debug logging
- Consider sorting the response in the same order as the trainNumber list from user
- Consider making parameters optional
- Consider splitting the implementation to couple modules instead of single
server.js
file