Query Parameters
1. Eager Loading (with
)
with
parameter allows you to include related data with the primary resource in a single API call. This reduces the need for multiple requests, improving performance.Usage:
?with=relation1,relation2
?with[]=relation1&with[]=relation2
Examples:
GET /api/user?with=company
GET /api/user?with[]=company&with[]=role
Nested Relations:
?with=relation.nested_relation
2. Partial Data (show
)
show
parameter allows clients to specify the fields they want to include in the response. This is useful for reducing payload size and focusing on necessary data.Usage:
?show=field1,field2
?show[]=field1&show[]=field2
Examples:
GET /api/resource?show=name,description
GET /api/resource?show[]=name&show[]=description
Nested Fields:
?show=field.nested_field
3. Count Relations (count
)
count
parameter allows clients to include the count of related resources for one-to-many or many-to-many relationships. Counts are returned as {relation_name}_count
fields.Usage:
?count=relation1,relation2
?count[]=relation1&count[]=relation2
Examples:
GET /api/customer?count=assignments
GET /api/customer?count=assignments,contracts
GET /api/customer?count[]=assignments&count[]=contracts
4. Pagination
Parameters:
offset
: The offset to retrieve items at. Default is 0
.limit
: The number of items per page. Default value is 100
.Examples:
GET /api/resource?offset=40&per_page=20
5. Filter (filter
)
filter
parameter enables clients to narrow down the results based on specific conditions.Format:
field:operator:value
and
/or
logic.Examples:
GET /api/resource?filter=field:operator:value
GET /api/resource?filter=field:eq:value,another_field:gt:10
?filter=field:eq:value,and,(field2:gt:5,or,field3:lt:10)
6. Order By (order_by
)
order_by
parameter allows clients to sort the response based on one or more fields.Usage:
?order_by=field:asc,another_field:desc
?order_by[]=field:asc&order_by[]=another_field:desc
Examples:
GET /api/resource?order_by=name:asc
GET /api/resource?order_by=name:asc,description:desc
GET /api/resource?order_by[]=name:asc&order_by[]=description:desc
Summary
Modified at 2025-01-26 14:35:32