Skip to main content

server

To load and import data from a remote URL. Server storage uses fetch API to send the call and fetch the data.

NameDescriptionTypeExample
urlServer base URLstringhttp://myapi.com
param.method optionalHTTP methodstringGET, POST, etc
param.headers optionalHTTP headersHeadersInit{ 'Accept-Charset': 'utf-8', 'X-My-Custom-Header': 'cool' }
pageUrl optionalURL to fetch the next pagestringhttp://myapi.com?page=2
pageBody optionalHTTP Body payloadBodyInit{ 'loginId': '@carry0987/paginator', 'password': 'd4da' }
processData optionalFunction to refine/select attributesFunction(data) => [data.name, data.email]
handle optionalFunction to handle the responseFunction(res) => res.json()
total optionalFunction to set the total recordsFunction(data) => data.total
new Paginator({
columns: ['Name', 'Language', 'Released At', 'Artist'],
server: {
url: 'https://api.scryfall.com/cards/search?q=Inspiring',
processData: (data) =>
data.data.map((card) => [
card.name,
card.lang,
card.released_at,
card.artist,
]),
handle: (res) => {
// no matching records found
if (res.status === 404) return { data: [] };
if (res.ok) return res.json();

throw Error('oh no :(');
},
},
});