Skip to content

Basic Usage

RubenJ01 edited this page Jan 18, 2026 · 2 revisions

Basic Usage

Most endpoints work the same way - you have three options depending on how many parameters you need:

Just the Basics

var artist = client.artists().getInfo("Cher");
var similar = client.artists().getSimilar("Cher");

One or Two Extra Options

var artist = client.artists().getInfo("Cher", "en");
var artist = client.artists().getInfo("Cher", true);
var similar = client.artists().getSimilar("Cher", 10);
var similar = client.artists().getSimilar("Cher", false, 20);

Everything Else (Including MBID)

Use the builder pattern for full control:

import io.github.rubeneekhof.lastfm.application.ArtistGetInfoRequest;

var artist = client.artists().getInfo(
    ArtistGetInfoRequest.artist("Cher")
        .lang("en")
        .autocorrect(true)
        .username("myusername")
        .build()
);

// or using MBID
var artist = client.artists().getInfo(
    ArtistGetInfoRequest.mbid("bfcc6d75-a6a5-4bc6-8282-47aec8531818")
        .build()
);

Builder pattern

Each endpoint has its own builder. Start with either artist("name") or mbid("id") - you need one of those. Then chain optional stuff before calling build():

ArtistGetInfoRequest.artist("Cher")    // required: start here
    .lang("en")                        // optional: biography language (ISO 639 code)
    .autocorrect(true)                 // optional: auto-fix typos (defaults vary by endpoint)
    .username("myusername")            // optional: include user-specific data
    .build()                           // required: creates the request object

If you forget to provide either an artist or MBID, build() will throw an exception. You can call the methods in any order and skip whatever you don't need.

Same pattern for all endpoints - albums, tracks, etc. all use their own builder classes.

Clone this wiki locally