lastfm-ts-api

Github Build Codacy Badge Codebeat Badge CodeFactor Badge DeepScan grade Analytics

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

GitHub stars GitHub forks GitHub watchers GitHub followers

Code stats

GitHub code size in bytes GitHub repo size GitHub language count GitHub top language GitHub last commit

Installation

npm install lastfm-ts-api

# or

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.

// To interact with the Album API:
import { LastFMAlbum } from 'lastfm-ts-api';

const album = new LastFMAlbum('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the Artist API:
import { LastFMArtist } from 'lastfm-ts-api';

const artist = new LastFMArtist('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the Auth API:
import { LastFMAuth } from 'lastfm-ts-api';

const auth = new LastFMAuth('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the Chart API:
import { LastFMChart } from 'lastfm-ts-api';

const chart = new LastFMChart('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the Geo API:
import { LastFMGeo } from 'lastfm-ts-api';

const geo = new LastFMGeo('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the Library API:
import { LastFMLibrary } from 'lastfm-ts-api';

const library = new LastFMLibrary('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the Tag API:
import { LastFMTag } from 'lastfm-ts-api';

const tag = new LastFMTag('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the Track API:
import { LastFMTrack } from 'lastfm-ts-api';

const track = new LastFMTrack('API_KEY', 'SECRET', 'SESSION_KEY');

// To interact with the User API:
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:

                     

Support and sponsor my work:

Send me your message

Trusted by

  • Duke University brand image
  • Emailio brand image
  • E.ON brand image
  • Kinetik Automotive brand image
  • Robert Ladkani brand image
  • SOD 64 brand image
  • Three11 brand image
  • dmarcian brand image
  • htmlBurger brand image
  • htmlBoutique brand image
  • 2create brand image