Request

Tokens and Paging: Running One Request Many Times

WithTokenFor(parameterName) finds that parameter wherever it appears, in the query string or in a JSON body, and replaces its value with the next numbered token: the first call makes {0}, the second {1}. WithTokensFrom then supplies the values, one row per set of requests, from a grid, a file, a database, or a plain comma separated string. Column 0 fills {0}, column 1 fills {1}. Paging is the same idea on a different axis: WithPages(int) says how many pages to walk, WithFirstPage(int) says what this API calls its first one, and WithPageToken(string) is the marker replaced with the page number, defaulting to {page}. CallAfterFetch runs after each row with that row's pages, and returning -1 from it stops the sweep.

NOTE

WithTokenFor works by finding the parameter name and replacing what follows it, so it fits query strings and flat JSON bodies. A value buried in a path segment, inside an array, or under a duplicate name is beyond it, and so is a request signed over its own parameters. When it does not fit, place the token yourself with WithParameter or WithBody and the rest still works.

Examples

GPAL Fluent: High-level fluent C# API

//SaveTo(ref string) hands back the response bodies as an array, one entry per request issued, in order. Position maps to the row and page that produced it, so a page that failed still occupies its place rather than shifting everything after it.

// One captured call becomes a template with two holes in it

rates.WithTokenFor("checkInDate") // becomes {0}

.WithTokenFor("checkOutDate") // becomes {1}

.CallAfterFetch(ReportNight);


// A row per night, and the sweep runs itself

IGPALGrid<string> nights = GPAL.GridForType<string>();

nights.AddRow(new List<string> { "2027-09-20", "2027-09-21" });

nights.AddRow(new List<string> { "2027-09-21", "2027-09-22" });


string json = null;

browser.WithTokensFrom(nights).Fetch(rates).SaveTo(ref json);


// Paging instead of tokens, when the API counts pages

browser.WithPages(10).Fetch(search).SaveTo(ref json);

💬 Ask GPAL