API reference
The following methods can be used to configure your Pages Function.
- onRequest(contextEventContext)Response | Promise<Response>- This function will be invoked on all requests no matter the request method.
 
- onRequestGet(contextEventContext)Response | Promise<Response>- This function will be invoked on all GETrequests.
 
- This function will be invoked on all 
- onRequestPost(contextEventContext)Response | Promise<Response>- This function will be invoked on all POSTrequests.
 
- This function will be invoked on all 
- onRequestPatch(contextEventContext)Response | Promise<Response>- This function will be invoked on all PATCHrequests.
 
- This function will be invoked on all 
- onRequestPut(contextEventContext)Response | Promise<Response>- This function will be invoked on all PUTrequests.
 
- This function will be invoked on all 
- onRequestDelete(contextEventContext)Response | Promise<Response>- This function will be invoked on all DELETErequests.
 
- This function will be invoked on all 
- onRequestHead(contextEventContext)Response | Promise<Response>- This function will be invoked on all HEADrequests.
 
- This function will be invoked on all 
- onRequestOptions(contextEventContext)Response | Promise<Response>- This function will be invoked on all OPTIONSrequests.
 
- This function will be invoked on all 
The env.ASSETS.fetch() function allows you to fetch a static asset from your Pages project.
You can pass a Request object, URL string, or URL object to env.ASSETS.fetch() function. The URL must be to the pretty path, not directly to the asset. For example, if you had the path /users/index.html, you will request /users/ instead of /users/index.html. This method call will run the header and redirect rules, modifying the response that is returned.
The following are the properties on the context object which are passed through on the onRequest methods:
- 
requestRequestThis is the incoming Request. 
- 
functionPathstringThis is the path of the request. 
- 
waitUntil(promisePromise<any>)voidRefer to waitUntildocumentation for more information.
- 
passThroughOnException()voidRefer to passThroughOnExceptiondocumentation for more information. Note that this will not work on an advanced mode project.
- 
next(input?Request | string, init?RequestInit)Promise<Response>Passes the request through to the next Function or to the asset server if no other Function is available. 
- 
envEnvWithFetch
- 
paramsParams<P>Holds the values from dynamic routing. In the following example, you have a dynamic path that is /users/[user].js. When you visit the site on/users/nevitheparamsobject would look like:{user: "nevi"}This allows you fetch the dynamic value from the path: export function onRequest(context) {return new Response(`Hello ${context.params.user}`);}Which would return "Hello nevi".
- 
dataData
Holds the environment variables, secrets, and bindings for a Function. This also holds the ASSETS binding which is how you can fallback to the asset-serving behavior.