Announcements

Help Wizard

Step 1

NEXT STEP

whyyy api. just why

whyyy api. just why

i just spent an embarrassing amount of openai assistant tokens to figure out that i have the reading comprehension skills of a goldfish.

 

api, why must you pluralize the object type in your response if the request is singular?

 

request:

curl --request GET url 'https://api.spotify.com/v1/search?q=PIG&type=artist&limit=20&offset=0' 

 

response:

{ "artists": { "href": "https://api.spotify.com/v1/search?query=PIG&type=artist&locale=en-US%2Cen%3Bq%3D0.9&offset=0&limit=2...", "limit": 20, ... } }

 

now i have to have an "s" just hanging around reminding me about this whole experience. forever.

def search(...)
...
response_key = f'{query_type}s' # Convert from singular to plural form
if response_key in result['data']:
items = [SpotifyMusicObject(item, {"type": query_type, "query": query})
for item in result['data'][response_key].get('items', [])]
return {'status': 'success', 'data': items}
Reply
1 Reply

Because `artist` is the type of the query, and the response returns a set of objects that have the type `artist`, it therefore makes sense to use artists in searching, since many artists can share the same name. For example, using your own query 'PIG', there are at least 5 artists whose names are 'PIG', the returned response contains all the artists whose names are 'PIG'. There's nothing wrong with the API design here.

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random