How to use the ky.create 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 pangolinjs / core / ui / src / api / index.js View on Github external
/* globals pangolinBase */

import ky from 'ky'

const connector = ky.create({
  prefixUrl: pangolinBase
})

export default {
  /**
   * Get project information
   */
  getProject () {
    return connector.get('pangolin/project.json').json()
  },
  /**
   * Get template list
   */
  getTemplates () {
    return connector.get('pangolin/templates.json').json()
  },
github xivanalysis / xivanalysis / src / api.ts View on Github external
import ky, {Options} from 'ky'
import _ from 'lodash'
import {Fight, ReportEventsQuery, ReportEventsResponse} from './fflogs'

const options: Options = {
	prefixUrl: process.env.REACT_APP_LOGS_BASE_URL,
}

if (process.env.REACT_APP_LOGS_API_KEY) {
	options.searchParams = {
		api_key: process.env.REACT_APP_LOGS_API_KEY,
	}
}

// Core API via ky
export const fflogsApi = ky.create(options)

async function requestEvents(code: string, searchParams: Record) {
	let response = await fflogsApi.get(
		`report/events/${code}`,
		{searchParams},
	).json()

	// If it's blank, try again, bypassing the cache
	if (response === '') {
		response = await fflogsApi.get(
			`report/events/${code}`,
			{searchParams: {...searchParams, bypassCache: 'true'}},
		).json()
	}

	// If it's _still_ blank, bail and get them to retry
github ralscha / blog2019 / ky / client / src / main.js View on Github external
async function customDefaults() {
  console.log('default ky');
  let body = await ky.get('simple-get', { prefixUrl: 'http://localhost:8080' }).text();
  console.log(body);

  console.log('custom ky with defaults');
  const customKy = ky.create({ prefixUrl: 'http://localhost:8080' });
  body = await customKy('simple-get').text();
  console.log(body);

  const customApiKy = customKy.extend({ headers: { 'x-api-key': '1111' } });
  body = await customApiKy('simple-get').text();
  console.log(body);
}
github Tosuke / submarine / src / infra / seaClient.ts View on Github external
constructor(readonly restEndpoint: string, readonly wsEndpoint: string, readonly seaToken: string) {
    this.http = ky.create({
      prefixUrl: restEndpoint,
      headers: [['Authorization', `Bearer ${seaToken}`]],
    })

    this.publicTimelineSocket = new RxWebSocket(() => {
      const ws = new WebSocket(wsEndpoint)
      ws.addEventListener('open', () => {
        ws.send(
          JSON.stringify({
            type: 'connect',
            stream: 'v1/timelines/public',
            token: seaToken,
          }),
        )
      })
      return ws
github atlasmap / atlasmap / ui-react / packages / atlasmap-core / src / AtlasmapProvider.tsx View on Github external
import {
  deleteAtlasFile,
  enableMappingPreview,
  exportAtlasFile,
  importAtlasFile,
  resetAtlasmap,
  documentExists,
} from './components/toolbar/toolbar-util';
import {
  FieldAction,
  FieldActionDefinition,
  Multiplicity,
} from './models/field-action.model';
import { MappedField } from './models/mapping.model';

const api = ky.create({ headers: { 'ATLASMAP-XSRF-TOKEN': 'awesome' } });

interface IAtlasmapContext extends State {
  dispatch: (value: Action) => void;
  initializationService: InitializationService;
}

const AtlasmapContext = createContext(null);

export interface IAtlasmapProviderProps {
  baseJavaInspectionServiceUrl: string;
  baseXMLInspectionServiceUrl: string;
  baseJSONInspectionServiceUrl: string;
  baseMappingServiceUrl: string;
}

interface State {
github otofu-square / realworld-react-redux / src / utils / apiClient.ts View on Github external
import ky from "ky";

export const apiClient = ky.create({
  prefixUrl: "https://conduit.productionready.io/api/",
  timeout: 5000,
  headers: {
    "Content-Type": "application/json"
  }
});

ky

Tiny and elegant HTTP client based on the browser Fetch API

MIT
Latest version published 11 days ago

Package Health Score

91 / 100
Full package analysis