3. The Artist data source
3m

🎯 Your goal for this step:

Add a new method to the class to retrieve artist-specific data

Artist data tasks

Use the following artist ID when completing these tasks.

An artist ID
3GBPw9NK25X1Wt2OUvOwY3

Solution: The Artist data source

models.ts
// Represents an artist object returned by the REST API's artists endpoint
export type ArtistModel = {
id: string;
name: string;
genres: string[];
uri: string;
followers: { total: number };
};
datasources/spotify-api.ts
import {
PlaylistModel,
TrackModel,
SnapshotOrError,
ArtistModel,
} from "../models";
export class SpotifyAPI extends RESTDataSource {
baseURL = "https://spotify-demo-api-fe224840a08c.herokuapp.com/v1/";
// ...other SpotifyAPI methods
async getArtist(artistId: string): Promise<ArtistModel> {
return this.get<ArtistModel>(`artists/${artistId}`);
}
}
Previous

Share your questions and comments about this lesson

Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.