Destructuring RequestEvent
When it comes to load()
, the server seems to have more information available to it than the client does. With so much data, it can be hard to know exactly all the information that is available. In short, server load()
functions are called with a SvelteKit-specific RequestEvent
. Here’s a quick breakdown of the properties (prop
) and functions (fn
) available from that object:
cookies
(prop
) – The cookies sent during the request.fetch
(fn
) – A compatible variant of the Web APIfetch()
function discussed in Chapter 3. It comes with the added benefit of allowing requests based on relative routes as well as passing cookies and headers through when on the same server.getClientAddress
(fn
) – Returns the client’s IP address.locals
(prop
) – Any custom data inserted into the request via SvelteKit’shandle()
hook. We’ll cover that in a later chapter.params
(prop
) – Parameters specific...