# Bun APIs

> Overview of Bun's native APIs available on the Bun global object and built-in modules

Bun implements a set of native APIs on the `Bun` global object and through several built-in modules. These APIs are heavily optimized and are the canonical "Bun-native" way to implement common functionality.

Bun strives to implement standard Web APIs wherever possible. Bun introduces new APIs primarily for server-side tasks where no standard exists, such as file I/O and starting an HTTP server. In these cases, Bun's approach still builds atop standard APIs like `Blob`, `URL`, and `Request`.

```ts server.ts icon="/icons/typescript.svg"
Bun.serve({
  fetch(req: Request) {
    return new Response("Success!");
  },
});
```

Use the links in the table to jump to the associated documentation.

| Topic                            | APIs                                                                                                                                                                                                                                                                                                                   |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| HTTP Server                      | [`Bun.serve`](https://bun.aphrody.com/docs/runtime/http/server)                                                                                                                                                                                                                                                                                    |
| Shell                            | [`$`](https://bun.aphrody.com/docs/runtime/shell)                                                                                                                                                                                                                                                                                                  |
| Bundler                          | [`Bun.build`](https://bun.aphrody.com/docs/bundler)                                                                                                                                                                                                                                                                                                |
| File I/O                         | [`Bun.file`](https://bun.aphrody.com/docs/runtime/file-io#reading-files-bun-file), [`Bun.write`](https://bun.aphrody.com/docs/runtime/file-io#writing-files-bun-write), `Bun.stdin`, `Bun.stdout`, `Bun.stderr`                                                                                                                                                                |
| Child Processes                  | [`Bun.spawn`](https://bun.aphrody.com/docs/runtime/child-process#spawn-a-process-bun-spawn), [`Bun.spawnSync`](https://bun.aphrody.com/docs/runtime/child-process#blocking-api-bun-spawnsync)                                                                                                                                                                                  |
| TCP Sockets                      | [`Bun.listen`](https://bun.aphrody.com/docs/runtime/networking/tcp#start-a-server-bun-listen), [`Bun.connect`](https://bun.aphrody.com/docs/runtime/networking/tcp#create-a-connection-bun-connect)                                                                                                                                                                            |
| UDP Sockets                      | [`Bun.udpSocket`](https://bun.aphrody.com/docs/runtime/networking/udp)                                                                                                                                                                                                                                                                             |
| WebSockets                       | `new WebSocket()` (client), [`Bun.serve`](https://bun.aphrody.com/docs/runtime/http/websockets) (server)                                                                                                                                                                                                                                           |
| Transpiler                       | [`Bun.Transpiler`](https://bun.aphrody.com/docs/runtime/transpiler)                                                                                                                                                                                                                                                                                |
| Routing                          | [`Bun.FileSystemRouter`](https://bun.aphrody.com/docs/runtime/file-system-router)                                                                                                                                                                                                                                                                  |
| Streaming HTML                   | [`HTMLRewriter`](https://bun.aphrody.com/docs/runtime/html-rewriter)                                                                                                                                                                                                                                                                               |
| Headless Browser                 | [`Bun.WebView`](https://bun.aphrody.com/docs/runtime/webview)                                                                                                                                                                                                                                                                                      |
| Hashing                          | [`Bun.password`](https://bun.aphrody.com/docs/runtime/hashing#bun-password), [`Bun.hash`](https://bun.aphrody.com/docs/runtime/hashing#bun-hash), [`Bun.CryptoHasher`](https://bun.aphrody.com/docs/runtime/hashing#bun-cryptohasher), `Bun.sha`                                                                                                                                                           |
| CSRF Protection                  | [`Bun.CSRF.generate`](https://bun.aphrody.com/docs/runtime/csrf), [`Bun.CSRF.verify`](https://bun.aphrody.com/docs/runtime/csrf)                                                                                                                                                                                                                                               |
| SQLite                           | [`bun:sqlite`](https://bun.aphrody.com/docs/runtime/sqlite)                                                                                                                                                                                                                                                                                        |
| SQL Client                       | [`Bun.SQL`](https://bun.aphrody.com/docs/runtime/sql), `Bun.sql`                                                                                                                                                                                                                                                                                   |
| Redis (Valkey) Client            | [`Bun.RedisClient`](https://bun.aphrody.com/docs/runtime/redis), `Bun.redis`                                                                                                                                                                                                                                                                       |
| FFI (Foreign Function Interface) | [`bun:ffi`](https://bun.aphrody.com/docs/runtime/ffi)                                                                                                                                                                                                                                                                                              |
| DNS                              | [`Bun.dns.lookup`](https://bun.aphrody.com/docs/runtime/networking/dns), `Bun.dns.prefetch`, `Bun.dns.getCacheStats`                                                                                                                                                                                                                               |
| Testing                          | [`bun:test`](https://bun.aphrody.com/docs/test)                                                                                                                                                                                                                                                                                                    |
| Workers                          | [`new Worker()`](https://bun.aphrody.com/docs/runtime/workers)                                                                                                                                                                                                                                                                                     |
| Module Loaders                   | [`Bun.plugin`](https://bun.aphrody.com/docs/bundler/plugins)                                                                                                                                                                                                                                                                                       |
| Glob                             | [`Bun.Glob`](https://bun.aphrody.com/docs/runtime/glob)                                                                                                                                                                                                                                                                                            |
| Cookies                          | [`Bun.Cookie`](https://bun.aphrody.com/docs/runtime/cookies), [`Bun.CookieMap`](https://bun.aphrody.com/docs/runtime/cookies)                                                                                                                                                                                                                                                  |
| Node-API                         | [`Node-API`](https://bun.aphrody.com/docs/runtime/node-api)                                                                                                                                                                                                                                                                                        |
| `import.meta`                    | [`import.meta`](https://bun.aphrody.com/docs/runtime/module-resolution#import-meta)                                                                                                                                                                                                                                                                |
| Utilities                        | [`Bun.version`](https://bun.aphrody.com/docs/runtime/utils#bun-version), [`Bun.revision`](https://bun.aphrody.com/docs/runtime/utils#bun-revision), [`Bun.env`](https://bun.aphrody.com/docs/runtime/utils#bun-env), [`Bun.main`](https://bun.aphrody.com/docs/runtime/utils#bun-main)                                                                                                                                                 |
| Sleep & Timing                   | [`Bun.sleep()`](https://bun.aphrody.com/docs/runtime/utils#bun-sleep), [`Bun.sleepSync()`](https://bun.aphrody.com/docs/runtime/utils#bun-sleepsync), [`Bun.nanoseconds()`](https://bun.aphrody.com/docs/runtime/utils#bun-nanoseconds)                                                                                                                                                                    |
| Random & UUID                    | [`Bun.randomUUIDv7()`](https://bun.aphrody.com/docs/runtime/utils#bun-randomuuidv7)                                                                                                                                                                                                                                                                |
| System & Environment             | [`Bun.which()`](https://bun.aphrody.com/docs/runtime/utils#bun-which)                                                                                                                                                                                                                                                                              |
| Comparison & Inspection          | [`Bun.peek()`](https://bun.aphrody.com/docs/runtime/utils#bun-peek), [`Bun.deepEquals()`](https://bun.aphrody.com/docs/runtime/utils#bun-deepequals), `Bun.deepMatch`, [`Bun.inspect()`](https://bun.aphrody.com/docs/runtime/utils#bun-inspect)                                                                                                                                                           |
| String & Text Processing         | [`Bun.escapeHTML()`](https://bun.aphrody.com/docs/runtime/utils#bun-escapehtml), [`Bun.stringWidth()`](https://bun.aphrody.com/docs/runtime/utils#bun-stringwidth), `Bun.indexOfLine`                                                                                                                                                                                          |
| URL & Path Utilities             | [`Bun.fileURLToPath()`](https://bun.aphrody.com/docs/runtime/utils#bun-fileurltopath), [`Bun.pathToFileURL()`](https://bun.aphrody.com/docs/runtime/utils#bun-pathtofileurl)                                                                                                                                                                                                   |
| Compression                      | [`Bun.gzipSync()`](https://bun.aphrody.com/docs/runtime/utils#bun-gzipsync), [`Bun.gunzipSync()`](https://bun.aphrody.com/docs/runtime/utils#bun-gunzipsync), [`Bun.deflateSync()`](https://bun.aphrody.com/docs/runtime/utils#bun-deflatesync), [`Bun.inflateSync()`](https://bun.aphrody.com/docs/runtime/utils#bun-inflatesync), `Bun.zstdCompressSync()`, `Bun.zstdDecompressSync()`, `Bun.zstdCompress()`, `Bun.zstdDecompress()` |
| Stream Processing                | [`Bun.readableStreamTo*()`](https://bun.aphrody.com/docs/runtime/utils#bun-readablestreamto), `Bun.readableStreamToBytes()`, `Bun.readableStreamToBlob()`, `Bun.readableStreamToFormData()`, `Bun.readableStreamToJSON()`, `Bun.readableStreamToArray()`                                                                                           |
| Memory & Buffer Management       | `Bun.ArrayBufferSink`, `Bun.allocUnsafe`, `Bun.concatArrayBuffers`                                                                                                                                                                                                                                                     |
| Module Resolution                | [`Bun.resolveSync()`](https://bun.aphrody.com/docs/runtime/utils#bun-resolvesync)                                                                                                                                                                                                                                                                  |
| Parsing & Formatting             | [`Bun.semver`](https://bun.aphrody.com/docs/runtime/semver), [`Bun.TOML.parse`](https://bun.aphrody.com/docs/runtime/toml), [`Bun.XML`](https://bun.aphrody.com/docs/runtime/xml), [`Bun.markdown`](https://bun.aphrody.com/docs/runtime/markdown), [`Bun.color`](https://bun.aphrody.com/docs/runtime/color), [`Bun.Image`](https://bun.aphrody.com/docs/runtime/image)                                                                                                                       |
| Low-level / Internals            | `Bun.mmap`, `Bun.gc`, `Bun.generateHeapSnapshot`, [`bun:jsc`](https://bun.com/reference/bun/jsc)                                                                                                                                                                                                                       |
