Skip to content

Commit

Permalink
released v0.2.2 - updated README to fix example code
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Mar 29, 2021
1 parent 556d9e1 commit f530e89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ const todos = [
{ id: '15', value: 'baz' },
]

// create a router (this is just an error-safe wrapper around itty router)
// create an error-safe itty router
const router = ThrowableRouter({ base: '/todos' })

// optional shortcut to avoid per-route calls
// optional [safe] shortcut to avoid per-route calls below
// router.all('*', withParams, withContent)

// GET collection index
Expand All @@ -67,12 +67,15 @@ router.get('/', () => asJSON(todos))
// GET item - only return if found
router.get('/:id', withParams, ({ id }) => {
const todo = todos.find(t => t.id === id)
if (todo) return json(todo)

if (todo) {
return json(todo)
}
})

// POST to the collection
router.post('/todos', withContent, ({ content }) => {
return content
router.post('/', withContent, ({ content }) =>
content
? json({
created: 'todo',
value: content,
Expand All @@ -85,7 +88,6 @@ router.all('*', () => missing('Are you sure about that?'))

// attach the router "handle" to the event handler
addEventListener('fetch', event =>
// router.handle expects a Request as the first param, then anything else gets passed along!
event.respondWith(router.handle(event.request))
)
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itty-router-extras",
"version": "0.2.1",
"version": "0.2.2",
"description": "An assortment of delicious extras for the calorie-light itty-router.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down

0 comments on commit f530e89

Please sign in to comment.