songlink-api
v1.0.0
Published
NodeJS client to query song.link's API
Downloads
2
Readme
song.link API
Simple client to query song.link's API.
Usage
This library exports the following two functions:
getLinks(params: SonglinkRequestParams, apiParams?: SonglinkAPIParams) => Promise<SonglinkResponse>
SongLinkParams
is described on song.link's docs for their API. You can check it here
SonglinkAPIParams
is an object containing two optional keys:
url
: URL to song.link's APIapiKey
: API Key as described here
Example:
import songlink from 'songlink-api'
songlink.getLinks({ url: 'https://open.spotify.com/track/5p3LIyy38s0QQNoSTwbZXX' })
.then(response => {
Object.entries(response.linksByPlatform)
.map(([platform, { url }]) => {
console.log(`Link for ${platform} is ${url}`)
})
console.log(`song.link URL is ${response.pageUrl}`)
})
getClient(apiParams: SonglinkAPIParams): (params: SonglinkRequestParams) => Promise
The types remain the same as in getLinks but this will return a new getLinks function, which does not require you to pass the API parameters every time.
This function is usefull in case you have an API key and intend to call getLinks
in various places of your code.
Example:
import songlink from 'songlink-api'
const myApiKey = process.env.SONGLINK_API_KEY
const getLinks = songlink.getClient({ apiKey: myApiKey })
getLinks({ url: 'https://open.spotify.com/track/5p3LIyy38s0QQNoSTwbZXX' })
.then(response => {
Object.entries(response.linksByPlatform)
.map(([platform, { url }]) => {
console.log(`Link for ${platform} is ${url}`)
})
console.log(`song.link URL is ${response.pageUrl}`)
})
TODOs
- [ ] Allow custom HTTP clients
- [ ] Allow options to be passed directly to axios