dsbmobile.js
A Javascript package for the DSBmobile API
Created Feb 25, 2022 - Last updated: Feb 25, 2022
dsbmobile
Digitales Schwarzes Brett (DSB) is an online-substitution plan that is widely used in Germany.
Why?
Since there was no package in JavaScript to interact with the dsbmobile API, I figured I had to make one.
Also, I needed the package for myDSB and other private projects.
How does it work?
As a User
Since the API only gave me an html response, I needed to parse the things I needed from that file, which isn’t the cleanest thing to do, but it works.
You can easily interact with the package like this:
import DSBmobile from "dsbmobile"
const api = new DSBmobile(<username>, <password>);
const table = await api.getTimetable()
and that’s all! Nothing more is needed to get the table, which is otherwise only displayed as an html file.
Behind the Scenes
While the NewsPost and DocumentPost are pretty normal http-requests, the Timetable is a bit more interesting, as the API responds with an HTML file. So when requesting the Time Table, I am receiving all of the information I need, but in a pretty bloated way. Using the cheerio package, I am iterating over certain parts of the HTML file to gather the information that I want.
Some difficulties
Because there is no official documentation of the dsbmobile API, I had to reverse engineer it to find out which routes, methods and data I need.