Skip to content

Commit df5e07d

Browse files
committed
docs
1 parent 836abf4 commit df5e07d

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

apps/docs/src/server/docs/04-helpers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Helpers
33
description: ovr route helpers.
44
---
55

6-
ovr provides helpers to encapsulate a route, allowing you to easily create a route in a separate module from `App`.
6+
ovr provides helpers to encapsulate a route, allowing you to easily create a route in a separate module from `App`. Helpers are the best way to create pages and API endpoints for an ovr application.
77

88
## Get
99

apps/docs/src/server/docs/05-context.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ description: Understanding the ovr request context.
77

88
## Request information
99

10-
Access information about the current request such as the `url` or [`params`](/06-routing#parameters).
10+
Access information about the current request such as the [`url`](https://developer.mozilla.org/en-US/docs/Web/API/URL) or [`params`](/06-routing#parameters).
1111

1212
```ts
1313
app.get("/api/:id", (c) => {
14-
c.req; // original Request
15-
c.url; // parsed URL
14+
c.req; // original `Request`
15+
c.url; // parsed web `URL`
1616
c.params; // type-safe route parameters { id: "123" }
17-
c.route; // matched Route (contains pattern, store)
17+
c.route; // matched `Route` (contains `pattern`, `store`)
1818
});
1919
```
2020

@@ -55,16 +55,32 @@ app.get("/api/:id", (c) => {
5555

5656
## Utilities
5757

58+
### Memo
59+
60+
Memoize a function to dedupe async operations and cache the results. See [memoization](/07-memo) for more details.
61+
5862
```tsx
5963
app.get("/api/:id", (c) => {
60-
// memoize a function to dedupe async operations and cache the results
6164
c.memo(fn);
65+
});
66+
```
67+
68+
### Entity tag
69+
70+
Generates an [entity tag](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag) from a hash of the string provided. If the tag matches, the response will be set to [`304: Not Modified`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304) and the funciton will return `true`.
71+
72+
```tsx
73+
app.get("/api/:id", (c) => {
74+
const html = `<p>Content</p>`;
75+
76+
const matched = c.etag(html);
6277

63-
// generate and check ETag for caching
64-
c.etag("content-to-hash");
78+
if (matched) {
79+
// 304: Not Modified
80+
return;
81+
}
6582

66-
// internal
67-
c.build(); // builds the final Response object
83+
return c.html(html);
6884
});
6985
```
7086

0 commit comments

Comments
 (0)