You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please make sure that icecast status-json.xslt returns a singleton array of source when there is a single source available, to allow consumers using an object-oriented model of icecast output for scraping.
As a programmer, I enjoy integrating open systems that speak popular protocols.
I was working on a mobile front end for icecast2 and I found that icecast exposes a JSON API to parse the available streams. I worked with Angular to process it.
I found that the JSON is generated by an XSL transform, which produces an output that in the REST paradigm is not easy to work with.
In XML, especially if you have a schema defined, you can easily tell whether the <source> tag appears once or multiple times, and multiple tags appear at the same level. In JSON, the source must be either an object or an array for the client to parse it easily
The problem is, look at these outputs when you have a single stream running, or multiple:
As you can see, if there is a single stream, then the object is a map. Otherwise, it's an array.
Software working on JSON has to suffer additional burden (i.e. more code, more tests, less reliability) to handle the icecast output compared to the straight solution of using an array for the source_s_.
This is for a Javascript FE. If I was using a C# or Java application, decoding icecast output into a POCO/POJO woulc be much harder. Defining a singleton array (i.e. an array containing one element) is the preferred solution in OO world,
I hope my feedback will be useful to improve the software
The text was updated successfully, but these errors were encountered:
TL:DR;
Please make sure that icecast status-json.xslt returns a singleton array of
source
when there is a single source available, to allow consumers using an object-oriented model of icecast output for scraping.As a programmer, I enjoy integrating open systems that speak popular protocols.
I was working on a mobile front end for icecast2 and I found that icecast exposes a JSON API to parse the available streams. I worked with Angular to process it.
I found that the JSON is generated by an XSL transform, which produces an output that in the REST paradigm is not easy to work with.
In XML, especially if you have a schema defined, you can easily tell whether the
<source>
tag appears once or multiple times, and multiple tags appear at the same level. In JSON, thesource
must be either an object or an array for the client to parse it easilyThe problem is, look at these outputs when you have a single stream running, or multiple:
As you can see, if there is a single stream, then the object is a map. Otherwise, it's an array.
Software working on JSON has to suffer additional burden (i.e. more code, more tests, less reliability) to handle the icecast output compared to the straight solution of using an array for the source_s_.
Here is my solution for an Angular app
And some typescript code to change the
IcecastSourceDto | IcecastSourceDto[]
into a (singleton?) arrayThis is for a Javascript FE. If I was using a C# or Java application, decoding icecast output into a POCO/POJO woulc be much harder. Defining a singleton array (i.e. an array containing one element) is the preferred solution in OO world,
I hope my feedback will be useful to improve the software
The text was updated successfully, but these errors were encountered: