Request

GPALRequest: A Request You Can Issue

GPALRequest is what CaptureCallTemplate hands back and what Fetch takes. CaptureCallTemplate(out GPALRequest) waits for the page to make a call matching the current WithCallFilter and hands it back as a request already carrying that call's url, method, body and headers. It can only follow WithCallFilter, since a template with no filter would be whichever call happened to be last. GPAL.Request builds one from nothing instead: WithPath (a path rides the origin the browser is on, a full url does not), WithHttpMethod, WithParameter("name=value") once per parameter, WithHeader("Name: value") once per header, WithBody, WithContentType, and WithName for what it is called in messages. ToGPALObject ends the chain.

WARNING

CaptureCallTemplate waits up to thirty seconds for a matching call and hands back null if none comes. That is the workflow's decision to make, not an exception, so check it before using it. A null usually means the filter was wrong or the page never made the call.

Examples

GPAL Fluent: High-level fluent C# API

//A captured template is worth more than a hand-written request because it carries the headers the page sent. Those are what the API expects and what a request built from the url alone is missing.

// Take the call the page makes, exactly as the page makes it

browser.WithCallFilter("/availability-api/stays-by-rooms")

.CaptureCallTemplate(out GPALRequest rates);


if (null == rates)

{

GPAL.PublishSimpleEvent(GPALEventType.FAILURE, "The page never made that call");

return;

}


// Or write one from nothing

GPALRequest search = GPAL.Request

.WithPath("/api/search")

.WithHttpMethod(HttpVerb.Post)

.WithParameter("size=50")

.WithHeader("Accept: application/json")

.WithBody("{"query":"boots"}")

.WithName("product search")

.ToGPALObject();

💬 Ask GPAL