Skip to content

Commit 669ef25

Browse files
committed
Add consistent alias functions for standard HTTP verb paths
1 parent 8b557a4 commit 669ef25

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

packages/fetch-router/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This is the changelog for [`fetch-router`](https://github.com/remix-run/remix/tr
3232
- Export `InferRouteHandler` and `InferRequestHandler` types
3333
- Re-export `FormDataParseError`, `FileUpload`, and `FileUploadHandler` from `@remix-run/form-data-parser`
3434
- Fix an issue where per-route middleware was not being applied to a route handler nested inside a route map with its own middleware
35+
- Adds functional aliases for routes that respond to a single HTTP verb
3536

3637
## v0.5.0 (2025-10-05)
3738

packages/fetch-router/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ export type {
3838

3939
export type { RouteHandlers, InferRouteHandler, RouteHandler } from './lib/route-handlers.ts'
4040

41+
export {
42+
createDelete,
43+
createDelete as delete, // shorthand
44+
createGet,
45+
createGet as get, // shorthand
46+
createPost,
47+
createPost as post, // shorthand
48+
createPut,
49+
createPut as put // shorthand
50+
} from './lib/route-helpers.ts'
51+
4152
export {
4253
Route,
4354
createRoutes,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { RoutePattern } from '@remix-run/route-pattern'
2+
3+
/**
4+
* Shorthand for a DELETE route.
5+
*/
6+
export function createDelete<P extends string>(pattern: P | RoutePattern<P>) {
7+
return { method: 'DELETE', pattern };
8+
}
9+
10+
/**
11+
* Shorthand for a GET route.
12+
*/
13+
export function createGet<P extends string>(pattern: P | RoutePattern<P>) {
14+
return { method: 'GET', pattern };
15+
}
16+
17+
/**
18+
* Shorthand for a POST route.
19+
*/
20+
export function createPost<P extends string>(pattern: P | RoutePattern<P>) {
21+
return { method: 'POST', pattern };
22+
}
23+
24+
/**
25+
* Shorthand for a PUT route.
26+
*/
27+
export function createPut<P extends string>(pattern: P | RoutePattern<P>) {
28+
return { method: 'PUT', pattern };
29+
}

0 commit comments

Comments
 (0)