@ta-interaktiv/api-access
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

API Access

This package centralises the access points to all the different APIs that are currently in use in this organisation.

Should the APIs change at some point (and they will), it should be possible to change this package and have all other packages that depend on API calls be updated automatically.

Usage

This package exports functions that return promises for the requested property.

Example: Share Counts for an article

import React, { useState, useEffect } from 'react'
import { getTotalShareCount } from '@ta-interaktiv/api-access'
import { parseHostname } from '@ta-interaktiv/parse-hostname'

export function YourComponent({ articleId }: { articleId: string }) {
  const [shareCount, setShareCount] = useState(0)

  useEffect(() => {
    // Get the share count for an article on a specific publication
    // Returns a promise
    getTotalShareCount(parseHostname().publicationName, articleId)
      // So you have to set the state here
      .then(count => setShareCount(count))
  }, [articleId])

  return <div>{shareCount}</div>
}

This package caches the requests to the API for each domain and article ID, so you can call these functions without having to fear that you flood the API endpoints with requests.

Readme

Keywords

Package Sidebar

Install

npm i @ta-interaktiv/api-access

Weekly Downloads

21

Version

1.1.0

License

MIT

Unpacked Size

109 kB

Total Files

46

Last publish

Collaborators

  • s1co
  • dariush-mehdiaraghi
  • mrdz_tx
  • mathiaslutz
  • sebaa