GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
GenerallyPositive.GPALRequest Class Reference

Describes an API request for .Fetch to issue from inside the page, so it carries the session the browser has already earned: its cookies, its TLS fingerprint, its header order and any anti-bot clearance.
Built once and reused, the same way a Selector is. Where a Selector says how to find an element, this says what to ask the site's own API for. More...

Inheritance diagram for GenerallyPositive.GPALRequest:
GenerallyPositive.IAllowRequestSettings GenerallyPositive.IAllowToGPALObject< TResult >

Public Member Functions

GPALRequest ToGPALObject ()
 Returns this request, so a chain can be assigned without an explicit cast.
IAllowRequestSettings WithPath (string path)
 Path or full URL to request. A path such as "/api/search" is resolved against the origin the browser is already on, which is what a site proxying its own API needs.
IAllowRequestSettings WithHttpMethod (Enums.HttpVerb method)
 HTTP method to use, for example GET, POST, PUT or DELETE. GET when nothing was said.
IAllowRequestSettings WithParameter (string nameValue)
 Adds a query parameter, written as "name=value". Call once per parameter.
IAllowRequestSettings WithTokenFor (string parameterName)
 Replaces the value of a query parameter with the next numbered token, so a request taken from a page can be varied without writing the url out again.
The first call makes it {0}, the next {1}, matching the columns .WithTokensFrom supplies.
IAllowRequestSettings WithHeader (string nameValue)
 Adds a request header, written as "Name: value". Call once per header. The browser sends its own headers regardless; these are added on top.
IAllowRequestSettings WithBody (string body)
 Body to send, used as-is. Sets the content type to application/json unless .WithContentType says otherwise.
IAllowRequestSettings WithContentType (Enums.ContentType contentType)
 Content type of the body. application/json when nothing was said.
IAllowRequestSettings WithFirstPage (int firstPage)
 What this API calls its first page, which is what the page token counts on from. Zero for Algolia and most search backends, one for many others. Zero when nothing was said.
IAllowRequestSettings WithPageToken (string token="{page}")
 The marker replaced with the page number, wherever it appears in the path, a parameter value, a header value or the body. Pick your own when the default would collide with the payload.
IAllowRequestSettings CallAfterFetch (Browser.Browser.CallAfterFetchDelegate callAfterFetch)
 Called after each row of tokens has been fetched, with that row's pages, so the workflow can work the results while the rest are still being retrieved. Unlike a page of a web site, .Fetch knows exactly what it is going to do, so the handler is declared here on the request rather than on the browser.
Return -1 to stop.
IAllowToGPALObject< GPALRequest > WithName (string name)
 Names the request for messages and errors. Narrows the interface, so it goes last.

Properties

string Path [get, set]
 Path or full URL to request. A path rides the origin the browser is already on.
string Method = "GET" [get, set]
 HTTP method. GET when nothing was said.
string Body [get, set]
 Request body, sent as-is.
string ContentType = "application/json" [get, set]
 Content type of the body.
List< KeyValuePair< string, string > > Parameters = new List<KeyValuePair<string, string>>() [get, set]
 Query parameters, in the order they were added.
List< KeyValuePair< string, string > > Headers = new List<KeyValuePair<string, string>>() [get, set]
 Extra request headers, on top of whatever the browser sends for itself.
int FirstPage [get, set]
 What the API calls its first page. Zero for Algolia and most search backends, one for many others. The page token counts on from here.
string PageToken = "{page}" [get, set]
 Marks where the page number goes. Put it anywhere .Fetch sends: the path, a parameter value, a header value or the body. It is a plain substring replacement, so GPAL never parses or understands what it is being put into, which is what lets a JSON body, a form post or an XML payload all page the same way. Change it with .WithPageToken when the default would collide with the payload.
Browser.Browser.CallAfterFetchDelegate AfterFetch [get, set]
 Called once per row of tokens, with that row's pages. Null when nothing was said.
string Name [get, set]
 Name used in messages and errors.

Detailed Description

Describes an API request for .Fetch to issue from inside the page, so it carries the session the browser has already earned: its cookies, its TLS fingerprint, its header order and any anti-bot clearance.
Built once and reused, the same way a Selector is. Where a Selector says how to find an element, this says what to ask the site's own API for.

static GPALRequest productSearch = (GPALRequest)GPAL.Request
.WithPath("/api/products/search")
.WithHttpMethod("POST")
.WithBody("{\"query\":\"{0}\",\"hitsPerPage\":{1},\"page\":{2}}")
.WithPageToken("{2}") // the row fills {0} and {1}, GPAL fills {2}
.CallAfterFetch(ProcessSearch)
.WithName("product search");
Everything starts here, all the GPAL controls and global settings using fluent syntax are here....
Definition GPAL.cs:49
static IAllowRequestSettings Request
Start describing an API request for .Fetch to issue from inside the page, so it carries the session t...
Definition GPAL.cs:724
Describes an API request for .Fetch to issue from inside the page, so it carries the session the brow...

Tokens are numbered to match the columns of whatever .WithTokensFrom was given, so {0} is the first column of the row, {1} the second, and so on. They are plain substring replacements and work anywhere .Fetch sends: the path, a parameter value, a header value or the body. Nothing here parses what it is writing into.

Definition at line 76 of file GPALRequest.cs.

Member Function Documentation

◆ CallAfterFetch()

IAllowRequestSettings GenerallyPositive.GPALRequest.CallAfterFetch ( Browser.Browser.CallAfterFetchDelegate callAfterFetch)

Called after each row of tokens has been fetched, with that row's pages, so the workflow can work the results while the rest are still being retrieved. Unlike a page of a web site, .Fetch knows exactly what it is going to do, so the handler is declared here on the request rather than on the browser.
Return -1 to stop.

Parameters
callAfterFetchHandler to call once per row of tokens
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 291 of file GPALRequest.cs.

◆ ToGPALObject()

GPALRequest GenerallyPositive.GPALRequest.ToGPALObject ( )

Returns this request, so a chain can be assigned without an explicit cast.

Returns
The request

Implements GenerallyPositive.IAllowToGPALObject< TResult >.

Definition at line 122 of file GPALRequest.cs.

◆ WithBody()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithBody ( string body)

Body to send, used as-is. Sets the content type to application/json unless .WithContentType says otherwise.

Parameters
bodyRequest body
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 242 of file GPALRequest.cs.

◆ WithContentType()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithContentType ( Enums.ContentType contentType)

Content type of the body. application/json when nothing was said.

Parameters
contentTypeContent type
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 253 of file GPALRequest.cs.

◆ WithFirstPage()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithFirstPage ( int firstPage)

What this API calls its first page, which is what the page token counts on from. Zero for Algolia and most search backends, one for many others. Zero when nothing was said.

Parameters
firstPageNumber of the first page
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 265 of file GPALRequest.cs.

◆ WithHeader()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithHeader ( string nameValue)

Adds a request header, written as "Name: value". Call once per header. The browser sends its own headers regardless; these are added on top.

Parameters
nameValueHeader as "Name: value"
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 230 of file GPALRequest.cs.

◆ WithHttpMethod()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithHttpMethod ( Enums.HttpVerb method)

HTTP method to use, for example GET, POST, PUT or DELETE. GET when nothing was said.

Parameters
methodHTTP method
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 144 of file GPALRequest.cs.

◆ WithName()

IAllowToGPALObject< GPALRequest > GenerallyPositive.GPALRequest.WithName ( string name)

Names the request for messages and errors. Narrows the interface, so it goes last.

Parameters
nameName of the request
Returns
Fluent interface to end the declaration

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 302 of file GPALRequest.cs.

◆ WithPageToken()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithPageToken ( string token = "{page}")

The marker replaced with the page number, wherever it appears in the path, a parameter value, a header value or the body. Pick your own when the default would collide with the payload.

Parameters
tokenMarker to replace. [{page} (default)]
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 277 of file GPALRequest.cs.

◆ WithParameter()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithParameter ( string nameValue)

Adds a query parameter, written as "name=value". Call once per parameter.

Parameters
nameValueParameter as "name=value"
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 155 of file GPALRequest.cs.

◆ WithPath()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithPath ( string path)

Path or full URL to request. A path such as "/api/search" is resolved against the origin the browser is already on, which is what a site proxying its own API needs.

Parameters
pathPath or full URL
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 133 of file GPALRequest.cs.

◆ WithTokenFor()

IAllowRequestSettings GenerallyPositive.GPALRequest.WithTokenFor ( string parameterName)

Replaces the value of a query parameter with the next numbered token, so a request taken from a page can be varied without writing the url out again.
The first call makes it {0}, the next {1}, matching the columns .WithTokensFrom supplies.

browser
.WithCallFilter("/availability-api/multiple-price-from")
.CaptureCallTemplate(out GPALRequest priceFrom);
priceFrom.WithTokenFor("startCheckDate"); // its value becomes {0}

Finds a named scalar, in a query parameter (?name=value, in the path or a form body) or a JSON field ("name": "value" or "name": 123). That covers most of what a site's own front end sends, and it does not cover everything:

  • A value that is a path segment rather than a parameter, such as the code in /hotels/ABC/rooms.
  • A value inside an array, such as "roomIds":["A","B"].
  • One name used twice with different meanings: every occurrence takes the same token.
  • Anything a signature or hash covers. Change it and the signature no longer matches, and no amount of templating fixes that.
  • Anything that is neither a query string nor JSON: GraphQL variables, XML, protobuf.
  • Values needing encoding. Substitution is literal, so the row supplies the encoded form.

None of that is a dead end. Tokens are only text, and .Fetch has always taken them anywhere in a path, parameter, header or body, so a shape this cannot reach is one you write the token into yourself:

.WithPath(captured.Path.Replace("ABC", "{0}"))
.WithBody(captured.Body)
.WithHttpMethod(HttpVerb.Post);
Parameters
parameterNameName of the query parameter or JSON field whose value becomes a token
Returns
Fluent interface to define the request more

Implements GenerallyPositive.IAllowRequestSettings.

Definition at line 199 of file GPALRequest.cs.

Property Documentation

◆ AfterFetch

Browser.Browser.CallAfterFetchDelegate GenerallyPositive.GPALRequest.AfterFetch
getset

Called once per row of tokens, with that row's pages. Null when nothing was said.

Definition at line 109 of file GPALRequest.cs.

◆ Body

string GenerallyPositive.GPALRequest.Body
getset

Request body, sent as-is.

Definition at line 85 of file GPALRequest.cs.

◆ ContentType

string GenerallyPositive.GPALRequest.ContentType = "application/json"
getset

Content type of the body.

Definition at line 88 of file GPALRequest.cs.

◆ FirstPage

int GenerallyPositive.GPALRequest.FirstPage
getset

What the API calls its first page. Zero for Algolia and most search backends, one for many others. The page token counts on from here.

Definition at line 98 of file GPALRequest.cs.

◆ Headers

List<KeyValuePair<string, string> > GenerallyPositive.GPALRequest.Headers = new List<KeyValuePair<string, string>>()
getset

Extra request headers, on top of whatever the browser sends for itself.

Definition at line 94 of file GPALRequest.cs.

◆ Method

string GenerallyPositive.GPALRequest.Method = "GET"
getset

HTTP method. GET when nothing was said.

Definition at line 82 of file GPALRequest.cs.

◆ Name

string GenerallyPositive.GPALRequest.Name
getset

Name used in messages and errors.

Definition at line 112 of file GPALRequest.cs.

◆ PageToken

string GenerallyPositive.GPALRequest.PageToken = "{page}"
getset

Marks where the page number goes. Put it anywhere .Fetch sends: the path, a parameter value, a header value or the body. It is a plain substring replacement, so GPAL never parses or understands what it is being put into, which is what lets a JSON body, a form post or an XML payload all page the same way. Change it with .WithPageToken when the default would collide with the payload.

Definition at line 106 of file GPALRequest.cs.

◆ Parameters

List<KeyValuePair<string, string> > GenerallyPositive.GPALRequest.Parameters = new List<KeyValuePair<string, string>>()
getset

Query parameters, in the order they were added.

Definition at line 91 of file GPALRequest.cs.

◆ Path

string GenerallyPositive.GPALRequest.Path
getset

Path or full URL to request. A path rides the origin the browser is already on.

Definition at line 79 of file GPALRequest.cs.


The documentation for this class was generated from the following file: