songlink-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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 API
  • apiKey: 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

Package Sidebar

Install

npm i songlink-api

Weekly Downloads

1

Version

1.0.0

License

GPL-3.0

Unpacked Size

6.56 kB

Total Files

9

Last publish

Collaborators

  • rjmunhoz