Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.

Commit b900b3c

Browse files
committed
Update README.md
1 parent 8dc4b20 commit b900b3c

1 file changed

Lines changed: 79 additions & 6 deletions

File tree

README.md

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
Framework agnostic transpilation utilities for client/server RPCs, env isolation, islands, module splitting, and more.
44

55
=======
6+
67
# API
78

8-
## `server$`
9+
## `serverFn$`
910

10-
The `server$` function is used to create a server-side RPC. It takes a function as its only argument, and returns a function that can be called from the client-side.
11+
The `serverFn$` function is used to create an isomorphic server-side RPC. It takes a function and an optional configuration object and returns a function that can be called on both server (ssr or ssg) and client. The function passed to `serverFn$` will only be executed on the server. On the client, a `fetch` call is made to the server function instead. The results of the function will be exactly the same on both server and client.
1112

1213
**🧠 Important Notes**:
1314

1415
- The server-side function must be an `async` function.
15-
- RPC's default to `POST` requests and pass payloads as request the request body. To use `GET` requests and search-param payloads instead, the `opts.method` can be set to `GET`. This will automatically configure both the method and the payload serialization to work via search params instead of a request body. You can also alter the actual request (and request body) manually to your liking.
16+
- The fetch calls made by the client default to using the `POST` method and passing arguments via the request body. To use `GET` requests and search-param payloads instead, the `opts.method` can be set to `GET`. This will automatically configure both the method and the payload serialization to work via search params instead of a request body. You can also alter the actual request (and request body) manually to your liking.
1617

1718
```tsx
18-
import { server$ } from '@tanstack/bling'
19+
import { serverFn$ } from '@tanstack/bling'
1920

20-
const serverFn = server$(async (payload) => {
21+
const serverFn = serverFn$(async (payload) => {
2122
// do something
2223
return 'result'
2324
})
@@ -26,7 +27,7 @@ const serverFn = server$(async (payload) => {
2627
### Signature
2728

2829
```tsx
29-
server$<T extends (...args: any[]) => any>(fn: T, options: {
30+
serverFn$<T extends (...args: any[]) => Promise<any>>(fn: T, options: {
3031
method?: 'POST' | 'GET' // Defaults to `POST`
3132
request?: RequestInit
3233
}): T
@@ -111,4 +112,76 @@ A function that can be called isomorphically from server or client side code to
111112
- The request object to be passed to the `fetch` call to the server function.
112113
- Can be used to add headers, signals, etc.
113114

115+
## `server$` (Coming Soon)
116+
117+
The `server$` function can be used to scope any expression to the server-bundle only. This means that the expression will be removed from the client bundle. This is useful for things like server-side only imports, or server-side only code.
118+
119+
```tsx
120+
import { server$ } from '@tanstack/bling'
121+
122+
const serverOnly = server$('It is a secret!')')
123+
```
124+
125+
Server Output:
126+
127+
```tsx
128+
const serverOnly = server$('It is a secret!')')
129+
```
130+
131+
Client Output:
132+
133+
```tsx
134+
const serverOnly = undefined
135+
```
136+
137+
### Signature
138+
139+
```tsx
140+
server$<T>(input: T): T | undefined
141+
```
142+
143+
### Arguments
144+
145+
- `input`
146+
- Any function, expression, or variable.
147+
148+
### Returns
149+
150+
- The variable on the server
151+
- `undefined` on the client
152+
153+
## `split$` (Coming Soon)
154+
155+
The `split$` function can be used to code-split any asynchronous function on both server and client at build-time.
156+
157+
```tsx
158+
import { split$ } from '@tanstack/bling'
159+
160+
const fn = split$(async (name: string) => {
161+
return `Hello ${name}`
162+
})
163+
```
164+
165+
Output:
166+
167+
```tsx
168+
const fn = (name: string) =>
169+
import('virtual:split$-[hash]').then((m) => m.default(name))
170+
```
171+
172+
### Signature
173+
174+
```tsx
175+
split$<T extends (...args: any[]) => Promise<any>>(fn: T): T
176+
```
177+
178+
### Arguments
179+
180+
- `fn`
181+
- The asynchronous function to be code-split.
182+
183+
### Returns
184+
185+
- A code-split version of the original function.
186+
114187
<!-- Use the force, Luke! -->

0 commit comments

Comments
 (0)