-
Notifications
You must be signed in to change notification settings - Fork 2.7k
docs(fetch-router): update readme blog example #10778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
|
||
| ```ts | ||
| import { resource, resources, createRoutes } from '@remix-run/fetch-router' | ||
|
|
@@ -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'), | ||
|
|
@@ -553,8 +552,7 @@ router.map(routes, { | |
| </html> | ||
| `) | ||
| }, | ||
| async update({ params, request }) { | ||
| let formData = await request.formData() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| async update({ formData, params, request }) { | ||
| await db.updatePost(params.slug, { | ||
| title: formData.get('title'), | ||
| content: formData.get('content'), | ||
|
|
@@ -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) } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
|
|
||
There was a problem hiding this comment.
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 :)