Path
path Method Documentation
The path method dynamically injects path parameters into a URL. This is useful for building RESTful endpoints by embedding values directly into the request path.
Note:
After finishing building your query attach .build(), .get() or .first() to generate it.
Method Signature
path(key: string, value: string | number): this
How It Works
key: The path parameter's name.value: The value to be substituted in the path, either as a string or number.
The method stores the provided key-value pair in pathParams and returns the current instance for chaining.
Use Cases
- Resource Identification: Specify unique resource identifiers in the URL.
- RESTful API Endpoints: Build dynamic endpoint URLs.
Examples
Single Path Parameter
query.path("userId", 42);
Multiple Path Parameters
query.path("userId", 42).path("postId", 99);
Dynamic Path Construction
const userId = 123;
const postId = 456;
query.path("userId", userId).path("postId", postId);
Summary Table
| Method Call | Generated URL | Description |
|---|---|---|
| query.path("userId", 42) | /users/42 | Adds a single path segment |
| query.path("userId", 42).path("postId", 99) | /users/42/posts/99 | Adds multiple path segments |