utilities
Script
Script
This val exports a function that loops through paginated API responses and returns the combined data as an array. It expects pagination with next
and there to be a data
property in the API response. This conforms to the Val Town API, so this function is useful when fetching paginated Val Town API responses for creating custom folders in pomdtr's vscode extension.
Usage:
const id = <vt user id>
await fetchPaginatedData(`https://api.val.town/v1/users/${id}/vals`, {
headers: { Authorization: `Bearer ${Deno.env.get("valtown")}` },
});
For demo usage in the context of the vscode extension see this val.
A helper function to take an array and return a paginated response. This is useful when defining one's own folders for pomdtr's vscode extension.
Usage:
const data = [...]
export default async function(req: Request): Promise<Response> {
return paginatedResponse(req, data);
}
For demo usage in the context of the vscode extension see this val.