Last.FM TypeScript API Client
A API client for the Last.FM API written in TypeScript
See the Last.FM API for information about the Last.Fm API, including details on how to register an account and get your API key, shared secret, and session key.
Visitor stats
Code stats
Installation
npm install lastfm-ts-api
yarn add lastfm-ts-api
Usage
lastfm-ts-api
exposes several classes which interact with different parts of the Last.FM API. These classes can be used to interact with the corresponding parts of the Last.FM API. First, you must instantiate these classes with arguments containing the details of your API account. apiKey
is required, however since many endpoints of the API do not require authentication, secret
and sessionKey
are optional.
import { LastFMAlbum } from 'lastfm-ts-api';
const album = new LastFMAlbum('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMArtist } from 'lastfm-ts-api';
const artist = new LastFMArtist('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMAuth } from 'lastfm-ts-api';
const auth = new LastFMAuth('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMChart } from 'lastfm-ts-api';
const chart = new LastFMChart('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMGeo } from 'lastfm-ts-api';
const geo = new LastFMGeo('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMLibrary } from 'lastfm-ts-api';
const library = new LastFMLibrary('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMTag } from 'lastfm-ts-api';
const tag = new LastFMTag('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMTrack } from 'lastfm-ts-api';
const track = new LastFMTrack('API_KEY', 'SECRET', 'SESSION_KEY');
import { LastFMUser } from 'lastfm-ts-api';
const user = new LastFMUser('API_KEY', 'SECRET', 'SESSION_KEY');
Making Requests
Each of the Last.FM classes contains methods which directly correspond to the Last.FM API methods.
For example, endpoint User.getRecentTracks
is accessed as user.getRecentTracks()
(after instantiating the class as described above).
Parameters can be passed to the API through the params
argument as an object that will be sent directly with the request, either as a query for a GET request, or a body for a POST request. The property names will not be transformed or abstracted, and so they must match the endpoint parameters exactly. This is where the TypeScript definitions play significant role - they get picked up by the IDE automatically so you don't need to worry about including/importing them.
user.getRecentTracks({
user: 'USER'
});
LICENSE
MIT
Connect with me: