Options
All
  • Public
  • Public/Protected
  • All
Menu

@paychex/adapter-xhr

Provides the top-level XHR Adapter that can be used in @paychex/core data pipelines.

// esm
import { xhr } from '@paychex/adapter-xhr';

// cjs
const { xhr } = require('@paychex/adapter-xhr');

// amd
define(['@paychex/adapter-xhr'], function({ xhr }) { ... });
require(['@paychex/adapter-xhr'], function({ xhr }) { ... });

// iife
const { xhr } = window['@paychex/adapter-xhr'];

Index

Interfaces

Type Aliases

Functions

Type Aliases

HeadersMap: Record<string, string | string[]>

Map of strings representing either Request headers or Response meta headers. The header name is the key and the header data is the value. If you pass an array of strings as the value, the strings will be combined and separated by commas.

example
import { fetch, createRequest } from '~/path/to/datalayer';

async function loadData() {
const request = createRequest({
base: 'my-app',
path: '/path/to/data',
headers: {
'content-type': 'application/json',
'accept': [
'application/json',
'text/plain',
'*∕*'
]
}
});
const response = await fetch(request);
console.log(response.meta.headers);
return response.data;
}

Functions

  • A data adapter that uses the XMLHttpRequest object to convert a Request into a Response. Can be passed to the @paychex/core createDataLayer factory method to enable data operations on NodeJS.

    example
    const proxy = data.createProxy();
    const { createRequest, fetch, setAdapter } = data.createDataLayer(proxy, xhr);

    Parameters

    • request: Request

      The Request to convert into a Response.

    Returns Promise<Response>

    A Response for the given Request.