Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/fetch-router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ router.map(routes, {

### Resource-based Routes

Create resource-based route maps with the `resource` and `resources` functions. This can help DRY up your route definitions when creating RESTful APIs, Rails-style routes, etc.
Create resource-based route maps with the `resource` and `resources` functions. This can help DRY up your route definitions when creating RESTful APIs, Rails-style routes, etc. This example illustrates [Rails-style routes](https://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those of us not familiar with Rails examples, just provide a link for clarity :)


```ts
import { resource, resources, createRoutes } from '@remix-run/fetch-router'
Expand Down Expand Up @@ -511,8 +511,7 @@ router.map(routes, {
</html>
`)
},
async create({ request }) {
let formData = await request.formData()
async create({ formData, request }) {
let post = await db.createPost({
title: formData.get('title'),
content: formData.get('content'),
Expand Down Expand Up @@ -553,8 +552,7 @@ router.map(routes, {
</html>
`)
},
async update({ params, request }) {
let formData = await request.formData()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work because the router is reading it (which I assume it needs to do in order to handle method overrides)

So need to get formData from the function rather than reading request.formData

async update({ formData, params, request }) {
await db.updatePost(params.slug, {
title: formData.get('title'),
content: formData.get('content'),
Expand All @@ -569,8 +567,16 @@ router.map(routes, {
})

export { router }

// Use the router in server environments that deal in request/response objects, e.g.
//
// ```
// import { router } from "./router"
// export default async function handler(req: Request) { return router.fetch(req) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note on how to integrate with hosting envs like deno.dev, val.town, etc. — might be useful for n00bs like myself

// ```
```


## Related Work

- [@remix-run/route-pattern](../route-pattern) - The pattern matching library that powers `fetch-router`
Expand Down