Get or set cookies related to the current request
fetch is equivalent to the native fetch web API, with a few additional features:
cookie and authorization headers for the page request.fetch requires a URL with an origin when used in a server context).+server.js routes) go directly to the handler function when running on the server, without the overhead of an HTTP call.text and json methods of the Response object. Note that headers will not be serialized, unless explicitly included via filterSerializedResponseHeadersYou can learn more about making credentialed requests with cookies here.
Optionalinit: RequestInitOptionalinit: RequestInitThe client's IP address, set by the adapter.
true if the request comes from the client asking for +page/layout.server.js data. The url property will be stripped of the internal information
related to the data request in this case. Use this property instead if the distinction is important to you.
true if the request comes from the client via a remote function. The url property will be stripped of the internal information
related to the data request in this case. Use this property instead if the distinction is important to you.
true for +server.js calls coming from SvelteKit without the overhead of actually making an HTTP request. This happens when you make same-origin fetch requests on the server.
Contains custom data that was added to the request within the server handle hook.
ReadonlyparamsAdditional data made available through the adapter.
The original request object.
ReadonlyrouteInfo about the current route.
If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
```js
/// file: src/routes/blog/+page.js
export async function load({ fetch, setHeaders }) {
const url = `https://cms.example.com/articles.json`;
const response = await fetch(url);
setHeaders({
age: response.headers.get('age'),
'cache-control': response.headers.get('cache-control')
});
return response.json();
}
```
Setting the same header multiple times (even in separate load functions) is an error — you can only set a given header once.
You cannot add a set-cookie header with setHeaders — use the cookies API instead.
Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
The span associated with the current handle hook, load function, or form action.
Whether tracing is enabled.
The root span for the request. This span is named sveltekit.handle.root.
The requested URL.
Enhanced RequestEvent passed into service handlers.
Adds
route.base,route.serviceand a rewrittenurlthat points at the service-relative path.