Skip to content

Commit 04fd4a4

Browse files
committed
docs(readme): update for Deno and Bun
1 parent 1aa71c9 commit 04fd4a4

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,46 @@ npm i -D @cloudflare/workers-types
2121
yarn add -D @cloudflare/workers-types
2222
```
2323

24-
## Write your code
24+
## Example
2525

2626
```ts
2727
// index.ts
2828
import { Pico } from '@picojs/pico'
2929

30+
// create Pico instance
3031
const app = new Pico()
3132

33+
// handle GET request and return TEXT response
3234
app.get('/', () => 'Hello Pico!')
33-
app.get('/entry/:id', ({ pathname }) => {
35+
36+
// capture the path parameter and return JSON response
37+
app.post('/entry/:id', ({ pathname }) => {
3438
const { id } = pathname.groups
3539
return {
3640
'your id is': id,
3741
}
3842
})
3943

44+
// get the query parameter
45+
app.get('/search', ({ search }) => {
46+
const params = new URLSearchParams(search.input)
47+
return `Your query is ${params.get('q')}`
48+
})
49+
50+
// handle the PURGE method and return Redirect response
51+
app.on('PURGE', '/cache', () => {
52+
return new Response(null, {
53+
status: 302,
54+
headers: {
55+
Location: '/',
56+
},
57+
})
58+
})
59+
60+
// return custom 404 response
61+
app.all('*', () => new Response('Custom 404', { status: 404 })
62+
63+
// export app for Cloudflare Workers
4064
export default app
4165
```
4266
@@ -52,6 +76,26 @@ wrangler dev index.ts
5276
wrangler publish index.ts
5377
```
5478
79+
## Bun
80+
81+
Now, Pico does not work on Bun because URLPattern may not be implemented yet.
82+
83+
## Deno
84+
85+
```ts
86+
import { serve } from 'https://deno.land/std/http/server.ts'
87+
import { Pico } from 'https://esm.sh/@picojs/pico'
88+
89+
const app = new Pico()
90+
app.get('/', () => 'Hi Deno!')
91+
92+
serve(app.fetch)
93+
```
94+
95+
```
96+
deno run -A pico.ts
97+
```
98+
5599
## Q&A
56100
57101
> What's the difference from Hono?

src/pico.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Pico extends defineDynamicClass() {
4646

4747
notFound = () => new Response('Not Found', { status: 404 })
4848

49-
fetch(request: Request) {
49+
fetch = (request: Request) => {
5050
const match = this.match(request.method, request.url)
5151
if (match === undefined) return this.notFound()
5252
const response = match.handler({ request, ...match.result })

0 commit comments

Comments
 (0)