How to use the ky.extend function in ky

To help you get started, we’ve selected a few ky examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github digidem / mapeo-mobile / src / frontend / api.js View on Github external
export function Api({
  baseUrl,
  timeout = DEFAULT_TIMEOUT
}: {
  baseUrl: string,
  timeout?: number
}) {
  let status: ServerStatus = STATUS.STARTING;
  let timeoutId: TimeoutID;
  // We append this to requests for presets and map styles, in order to override
  // the local static server cache whenever the app is restarted. NB. sprite,
  // font, and map tile requests might still be cached, only changes in the map
  // style will be cache-busted.
  const startupTime = Date.now();

  const req = ky.extend({
    prefixUrl: baseUrl,
    // No timeout because indexing after first sync takes a long time, which mean
    // requests to the server take a long time
    timeout: false,
    headers: {
      "cache-control": "no-cache",
      pragma: "no-cache"
    }
  });

  const pending: Array<{ resolve: () => any, reject: Error => any }> = [];
  let listeners: Array<(status: ServerStatus) => any> = [];

  nodejs.channel.addListener("status", onStatusChange);

  function onStatusChange(newStatus: ServerStatus) {
github LinusBorg / composition-api-demos / src / api / index.js View on Github external
import Ky from 'ky'
import useEndpoint from '@/composables/use-endpoint'
const BASE_URL = 'https://jsonplaceholder.typicode.com'

const ky = Ky.extend({
  prefixUrl: BASE_URL,
})

const POSTS_URL = 'posts'
const IMAGES_URL = 'photos'

function getPosts({ start = 0, limit = 5 } = {}) {
  return wait(
    ky(POSTS_URL, {
      searchParams: {
        _start: start,
        _limit: limit,
      },
    }).json()
  )
}
github bojand / ghz / web / ui / src / containers / ReportContainer.js View on Github external
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'

import { getAppRoot } from '../lib/common'

const api = ky.extend({ prefixUrl: getAppRoot() + '/api/' })

export default class ReportContainer extends Container {
  constructor (props) {
    super(props)
    this.state = {
      total: 0,
      reports: [],
      currentReport: {},
      isFetching: false
    }
  }

  async fetchReports (order = 'desc', sort = 'date', page = 0, projectId = 0) {
    this.setState({
      isFetching: true
    })
github bojand / ghz / web / ui / src / containers / ProjectContainer.js View on Github external
import { Container } from 'unstated'
import ky from 'ky'
import _ from 'lodash'
import { toaster } from 'evergreen-ui'

import { getAppRoot } from '../lib/common'

const api = ky.extend({ prefixUrl: getAppRoot() + '/api/' })

export default class ProjectContainer extends Container {
  constructor (props) {
    super(props)
    this.state = {
      totalProjects: 0,
      projects: [],
      isFetching: false,
      currentProject: {}
    }
  }

  async fetchProjects (order = 'desc', page = 0) {
    this.setState({
      isFetching: true
    })
github bojand / ghz / web / ui / src / containers / OptionsContainer.js View on Github external
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'

import { getAppRoot } from '../lib/common'

const api = ky.extend({ prefixUrl: getAppRoot() + '/api/reports/' })

export default class OptionsContainer extends Container {
  constructor (props) {
    super(props)
    this.state = {
      options: 0,
      isFetching: false
    }
  }

  async fetchOptions (reportId) {
    this.setState({
      isFetching: true
    })

    try {
github bojand / ghz / web / ui / src / containers / CompareContainer.js View on Github external
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'

import { getAppRoot } from '../lib/common'

const api = ky.extend({ prefixUrl: getAppRoot() + '/api/reports/' })

export default class CompareContainer extends Container {
  constructor (props) {
    super(props)
    this.state = {
      report1: null,
      report2: null,
      isFetching: false
    }
  }

  async fetchReports (reportId1, reportId2) {
    this.setState({
      isFetching: true
    })
github bitcrowd / tickety-tick / src / common / client.js View on Github external
function client(base, options = {}) {
  return ky.extend({
    prefixUrl: base,
    credentials,
    headers,
    timeout,
    ...options,
  });
}
github bojand / ghz / web / ui / src / containers / InfoContainer.js View on Github external
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'

import { getAppRoot } from '../lib/common'

const api = ky.extend({ prefixUrl: getAppRoot() + '/api/' })

export default class InfoContainer extends Container {
  constructor (props) {
    super(props)

    this.state = {
      info: null,
      isFetching: false
    }
  }

  async fetchInfo () {
    this.setState({
      isFetching: true
    })
github bojand / ghz / web / ui / src / containers / HistogramContainer.js View on Github external
import { Container } from 'unstated'
import ky from 'ky'
import { toaster } from 'evergreen-ui'

import { getAppRoot } from '../lib/common'

const api = ky.extend({ prefixUrl: getAppRoot() + '/api/reports/' })

export default class HistogramContainer extends Container {
  constructor (props) {
    super(props)
    this.state = {
      histogram: 0,
      isFetching: false
    }
  }

  async fetchHistogram (reportId) {
    this.setState({
      isFetching: true
    })

    try {

ky

Tiny and elegant HTTP client based on the Fetch API

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis