[2.0.0] - 2025-12-14
⚠️ Breaking Changes
- Removed legacy API support - The deprecated
requiredProps,defaultProps,pathParams, andqueryParamsoptions have been completely removed. You must use the unifiedoptionsarray instead. - Path params are now auto-extracted - Path parameters are automatically extracted from the endpoint string (e.g.,
/users/:userId). You no longer need to define them. - Function names are auto-generated - Function names are now automatically generated from the HTTP method:
GET→fetchDataPOST→postDataPUT→putDataPATCH→patchDataDELETE→deleteData
- New function signature - Functions now accept grouped parameters:
fetchData({ path: { userId: "123" }, header: { Authorization: "Bearer token" }, body: { name: "John" }, query: { lang: "en" } })
- Endpoint is now string only - The
endpointproperty no longer accepts functions, only strings.
Added
- Unified
optionsarray configuration - New unified way to define API parameters using a singleoptionsarray ParamLocationtype with support for"query","header", and"body"locations (path params are auto-extracted)ApiParam<T>interface for type-safe parameter definitionsparam<T>()helper function for improved TypeScript type inference- Support for header parameters via the options array
- Support for body parameters via the options array
- Automatic path parameter extraction - Path params are automatically extracted from endpoint strings (e.g.,
/users/:userId) - Automatic function name generation - Function names are auto-generated from HTTP methods
- Grouped parameter structure - Parameters are now passed grouped by location (
path,header,body,query) - Simplified parameter requirements - Options with
defaultValueare always optional (implicit), reducing boilerplate
Changed
- Improved type inference for parameter values using the
valueTypeproperty inApiParam - Better organization of parameter configuration - each parameter is now defined once with all its properties
- Function calls now use grouped parameters for better clarity and organization
Example Migration
Before (v1.x):
const useGetUser = createApiHook({
method: "GET",
baseURL: "https://api.example.com",
endpoint: "/users/:userId",
requiredProps: ["userId"],
defaultProps: { lang: "en_US" },
pathParams: ["userId"],
queryParams: ["lang"],
});
// Usage
fetchData({ userId: "123", lang: "es_ES" });After (v2.0.0):
const useGetUser = createApiHook({
method: "GET",
baseURL: "https://api.example.com",
endpoint: "/users/:userId",
// Path params are automatically extracted from endpoint
options: [
{ key: "lang", location: "query", defaultValue: "en_US" },
],
});
// Usage with grouped params
fetchData({
path: { userId: "123" },
query: { lang: "es_ES" }
});Key Changes:
- Path params are automatically extracted from endpoint - no need to define them
- Function names are auto-generated (GET→
fetchData, POST→postData, etc.) - Parameters are grouped by location in function calls
- Options with
defaultValueare optional (implicit)
Full Changelog: https://github.com/Xarlizard/react-api-forge/blob/main/CHANGELOG.md