Skip to content

Uses the unofficial API of the "Kieler Verkehrsgesellschaften" (KVG) to provide an API endpoint (Express Server).

Notifications You must be signed in to change notification settings

maxverwiebe/KVG-ExpressAPI

Repository files navigation

KVG-ExpressAPI 🚀

GitHub stars GitHub forks GitHub issues GitHub pull requests License

A modern API built with Express.js for retreiving realtime data of the "Kieler Verkehrsgesellschaft" (KVG) data.

🌟 Features

  • Fast and Efficient: Built with performance in mind.
  • Easy to Use: Simple endpoints with clear documentation.
  • Scalable: Ready to handle large amounts of data.
  • Secure: The endpoints are only accessable with a valid key

🚀 Getting Started

  1. Clone the repository:

    git clone https://github.com/maxverwiebe/KVG-ExpressAPI.git
  2. Install dependencies:

    npm install
  3. Adjust the configuation file:

    ./config.json
  4. Start the server:

    node server/index.js

⚙️ Generating the .csv

The generator sends requests to the unofficial API of the KVG to assign the stop name to each ID. The result is stored in a csv file.

  1. Adapt the search range in:

    tools/csv_generator_improved.js
  2. Start the generation:

    node tools/csv_generator_improved.js

Endpoints

1. /request_kvg

  • Method: GET
  • Description: A basic endpoint for testing.
  • Headers:
    • X-API-KEY: Your API key
  • Responses:
    • 200 OK: Successful request
    • 401 Unauthorized: Missing API key
    • 403 Forbidden: Invalid API key

2. /stations/get_departing_busses/:type/:id

  • Method: GET
  • Description: Fetches departing buses from a station.
  • Parameters:
    • type: Can be "name" or "id"
    • id: The station name or ID
  • Headers:
    • X-API-KEY: Your API key
  • Responses:
    • 200 OK: Successful request with JSON data
    • 401 Unauthorized: Missing API key
    • 403 Forbidden: Invalid API key
    • 404 Not Found: Bus station not found
    • 500 Internal Server Error: Error fetching station ID

3. /stations/get_busses/:type/:id

  • Method: GET
  • Description: Fetches all buses from a station.
  • Parameters:
    • type: Can be "name" or "id"
    • id: The station name or ID
  • Headers:
    • X-API-KEY: Your API key
  • Responses:
    • 200 OK: Successful request with JSON data
    • 401 Unauthorized: Missing API key
    • 403 Forbidden: Invalid API key
    • 404 Not Found: Bus station not found
    • 500 Internal Server Error: Error fetching station ID

Example using Axios:

const axios = require('axios');

axios.get('http://your-api-url/stations/get_busses/name/StationName', {
  headers: {
    'X-API-KEY': 'your-api-key'
  }
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error('Error:', error);
});

4. /trips/get_trip/:id

  • Method: GET
  • Description: Fetches information about a running trip.
  • Parameters:
    • id: The station name or ID
  • Headers:
    • X-API-KEY: Your API key
  • Responses:
    • 200 OK: Successful request with JSON data
    • 401 Unauthorized: Missing API key
    • 403 Forbidden: Invalid API key
    • 404 Not Found: Bus station not found
    • 500 Internal Server Error: Error fetching station ID

🤝 Contributing

Contributions, issues, and feature requests are welcome!

📜 License

This project is MIT licensed.

About

Uses the unofficial API of the "Kieler Verkehrsgesellschaften" (KVG) to provide an API endpoint (Express Server).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published