---
title: "Base64Url Helpers"
description: "Encode and decode URL-safe base64url strings with oRPC helpers, useful for web tokens, data serialization, and APIs."
sidebar:
  label: "Base64Url"
---

## Basic Usage

```ts twoslash
import { decodeBase64url, encodeBase64url } from '@orpc/server/helpers'

const originalText = 'Hello World'
const textBytes = new TextEncoder().encode(originalText)
const encodedData = encodeBase64url(textBytes)
const decodedBytes = decodeBase64url(encodedData)
const decodedText = new TextDecoder().decode(decodedBytes) // 'Hello World'
```

:::info
The `decodeBase64url` accepts `undefined` or `null` as encoded value and returns `undefined` for invalid inputs, enabling seamless handling of optional data.

It only accepts canonical, unpadded base64url, the exact form `encodeBase64url` produces. Anything else returns `undefined`, including padded (`=`) or standard base64 (`+`, `/`) input, whitespace, and strings whose unused trailing bits are not zero.
:::
