40 Web Standards
40 Web Standards
Throughout this documentation, you'll see references to the standard [Web APIs]
(https://developer.mozilla.org/en-US/docs/Web/API) that SvelteKit builds on top of.
Rather than reinventing the wheel, we _use the platform_, which means your existing
web development skills are applicable to SvelteKit. Conversely, time spent learning
SvelteKit will help you be a better web developer elsewhere.
These APIs are available in all modern browsers and in many non-browser
environments like Cloudflare Workers, Deno and Vercel Edge Functions. During
development, and in [adapters](adapters) for Node-based environments (including AWS
Lambda), they're made available via polyfills where necessary (for now, that is —
Node is rapidly adding support for more web standards).
## Fetch APIs
### Request
An instance of
[`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) is accessible
in [hooks](hooks) and [server routes](routing#server) as `event.request`. It
contains useful methods like `request.json()` and `request.formData()` for getting
data that was posted to an endpoint.
### Response
An instance of
[`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) is returned
from `await fetch(...)` and handlers in `+server.js` files. Fundamentally, a
SvelteKit app is a machine for turning a `Request` into a `Response`.
### Headers
## FormData
When dealing with HTML native form submissions you'll be working with [`FormData`]
(https://developer.mozilla.org/en-US/docs/Web/API/FormData) objects.
```js
// @errors: 2461
/// file: src/routes/hello/+server.js
import { json } from '@sveltejs/kit';
return json({
// get a specific field's value
name: body.get('name') ?? 'world'
});
}
```
## Stream APIs
Most of the time, your endpoints will return complete data, as in the `userAgent`
example above. Sometimes, you may need to return a response that's too large to fit
in memory in one go, or is delivered in chunks, and for this the platform provides
[streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) —
[ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream),
[WritableStream](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)
and [TransformStream](https://developer.mozilla.org/en-US/docs/Web/API/
TransformStream).
## URL APIs
### URLSearchParams
Wherever you encounter a URL, you can access query parameters via
`url.searchParams`, which is an instance of
[`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/
URLSearchParams):
```js
// @filename: ambient.d.ts
declare global {
const url: URL;
}
export {};
// @filename: index.js
// ---cut---
const foo = url.searchParams.get('foo');
```
## Web Crypto
```js
const uuid = crypto.randomUUID();
```