A simple API library for interacting with Subsonic-compatible servers (Up to API version 1.16.1) written in TypeScript.
$ npm install subsonic-api
You can also try out the example on CodeSandbox here.
import { SubsonicAPI } from "subsonic-api";
const api = new SubsonicAPI({
url: "https://demo.navidrome.org",
type: "navidrome", // or "generic" or "subsonic"
});
await api.login({
username: "demo",
password: "demo",
});
const { randomSongs } = await api.getRandomSongs();
console.log(randomSongs);
subsonic-api
supports all of the Subsonic API methods as documented here, up to API version 1.16.1 / Subsonic 6.1.4.
All methods return a promise that resolves to the JSON response from the server.
Additionally, the following methods are available:
login(options: LoginOptions): Promise<void>
Logs in to the server and stores the password for future requests.
interface LoginOptions {
username: string;
password: string;
}
custom(method: string, params: Params): Promise<Response>
Allows you to make a custom request to the server.
customJSON<T>(method: string, params: Params): Promise<T>
Allows you to make a custom request to the server and parse the response as JSON.