Skip to content

Commit 093b92f

Browse files
committed
chore: update readme
1 parent b6e8181 commit 093b92f

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ Use `<? ... ?>` for JavaScript control flow:
117117
118118
Use `echo()` function for streaming content. Accepts: strings, functions, Promises, Response objects, or ReadableStreams:
119119
120+
121+
**Examples:**
120122
```html
123+
<!-- Simple string output -->
124+
<script server>
125+
echo("Welcome to our site!");
126+
</script>
127+
128+
<!-- Async content from API (non blocking)-->
121129
<script server>
122130
echo("Hello");
123131
echo(async () => fetch("https://api.example.com/data"));
@@ -133,10 +141,47 @@ Access request context and global state:
133141
- `$METHOD`: HTTP method (GET, POST, etc.)
134142
- `$URL`: Request URL object
135143
- `$HEADERS`: Request headers
144+
- `$COOKIES`: Read-only object containing request cookies
136145
- `$RESPONSE`: Response configuration object
137-
- `$GLOBALS`: Global state object
138146
- `globalThis`: Global JavaScript object
139147
148+
### Cookie Management
149+
150+
Use `setCookie()` function to set cookies in the response:
151+
152+
```html
153+
<script server>
154+
setCookie("user", "RenduUser");
155+
setCookie("session", "abc123", { maxAge: 3600, httpOnly: true });
156+
</script>
157+
```
158+
159+
Access cookies from the request using `$COOKIES`:
160+
161+
```html
162+
<div>Welcome, <?= $COOKIES["user"] || "Guest" ?>!</div>
163+
```
164+
165+
### Response Control
166+
167+
Use `redirect()` function to redirect the user:
168+
169+
```html
170+
<script server>
171+
if (!$COOKIES["auth"]) {
172+
redirect("/login");
173+
}
174+
</script>
175+
```
176+
177+
### HTML Escaping
178+
179+
The `htmlspecialchars()` function is available for escaping HTML content:
180+
181+
```html
182+
<div><?= htmlspecialchars(userInput) ?></div>
183+
```
184+
140185
## Development
141186
142187
<details>

0 commit comments

Comments
 (0)