|
1 | 1 | # what-the-fetch |
2 | 2 |
|
| 3 | +## 2.2.0 |
| 4 | + |
| 5 | +### Minor Changes |
| 6 | + |
| 7 | +- b5be69a: Add HTTP method prefix notation (@method/path) for declaring methods in API schema paths |
| 8 | + |
| 9 | + ### New Feature: HTTP Method Prefix Notation |
| 10 | + |
| 11 | + You can now declare HTTP methods directly in API schema paths using the `@method/path` syntax: |
| 12 | + |
| 13 | + ```typescript |
| 14 | + const api = { |
| 15 | + "@get/users": { |
| 16 | + response: z.array(z.object({ id: z.number(), name: z.string() })), |
| 17 | + }, |
| 18 | + "@post/users": { |
| 19 | + body: z.object({ name: z.string(), email: z.string() }), |
| 20 | + response: z.object({ |
| 21 | + id: z.number(), |
| 22 | + name: z.string(), |
| 23 | + email: z.string(), |
| 24 | + }), |
| 25 | + }, |
| 26 | + "@put/users/:id": { |
| 27 | + params: z.object({ id: z.number() }), |
| 28 | + body: z.object({ name: z.string() }), |
| 29 | + response: z.object({ id: z.number(), name: z.string() }), |
| 30 | + }, |
| 31 | + } as const; |
| 32 | + ``` |
| 33 | + |
| 34 | + **Key Features:** |
| 35 | + |
| 36 | + - Supports all HTTP methods: `@get`, `@post`, `@put`, `@delete`, `@patch`, etc. |
| 37 | + - Method names are case-insensitive (normalized to uppercase) |
| 38 | + - `@get/api` is equivalent to `/api` in URL, only the HTTP method differs |
| 39 | + - Backward compatible: paths without prefix continue to work as before |
| 40 | + - Type-safe: `RequestInit` parameters are now `Omit<RequestInit, 'method'>` to prevent method override |
| 41 | + |
| 42 | + **Implementation:** |
| 43 | + |
| 44 | + - Added `parseMethodFromPath()` utility function to extract method prefix |
| 45 | + - Updated `createFetch()` to use the extracted method from path prefix |
| 46 | + - Restricted `RequestInit` types to prevent method override |
| 47 | + |
| 48 | +### Patch Changes |
| 49 | + |
| 50 | +- 52df593: Update `fast-url` dependency to version 6.0.2 for significant performance optimizations. This release includes: |
| 51 | + |
| 52 | + - **Pre-compiled regex**: Path parameter regex is now extracted to module scope to avoid recompilation on every `path()` call, improving efficiency for path template processing |
| 53 | + - **Optimized string joining**: URL joining now uses direct string indexing instead of `endsWith`/`startsWith` methods, with fast paths for empty strings and common scenarios, reducing unnecessary string slicing |
| 54 | + - **Optimized parameter filtering**: The `removeNullOrUndef()` function now checks for null/undefined values before allocating new objects and uses direct property iteration instead of `Object.entries`/`Object.fromEntries`, resulting in faster execution and less memory usage |
| 55 | + |
| 56 | + For full details, see the [fast-url 6.0.2 release notes](https://github.com/hckhanh/fast-url/releases/tag/fast-url%406.0.2). |
| 57 | + |
3 | 58 | ## 2.1.0 |
4 | 59 |
|
5 | 60 | ### Minor Changes |
|
0 commit comments