Request Parameter Collections
Working with API Operations that have a large parameter list can be messy. Grouping the parameters of such Endpoints into a single structured collection such as a data model, map or dictionary can make the code cleaner and easier to read. APIMatic allows users to apply this approach to their SDKs, either globally or to specific Operations.
Creating Request Parameter Collections
To enable this feature globally for the entire SDK, set the collectParameters
CodeGen setting to true
. You can also configure it at the operation level by setting the collectParameters
option under the x-operation-settings
OpenAPI Extension as demonstrated below:
openapi: 3.0.3
info:
title: Product Management API
description: API for managing products in an inventory system.
version: 1.0.0
paths:
/products/filter:
get:
summary: Retrieve filtered products
x-operation-settings:
collectParameters: true
parameters:
- name: category
in: query
description: Product category to filter by
required: true
schema:
type: string
example: "Electronics"
- name: price
in: query
description: Range of product prices
required: true
schema:
type: string
example: "100-500"
In this example, the /products/filter
operation uses the Collect Parameters feature, which groups the category
and priceRange
parameters into a single collection for easier use.
SDK Usage Examples
- TypeScript
- Java
- Python
- PHP
- .NET
- Ruby
- Go
const apiController = new ApiController(client);
// Using a single collection for parameters in TypeScript
const collect = {
category: 'Electronics',
price: '100-500'
}
await apiController.getFilteredProducts(collect)
ApiController apiController = client.getApiController();
// Using a Model to pass parameters in Java
GetFilteredProductsInput getFilteredProductsInput = new GetFilteredProductsInput.Builder(
"Electronics",
"100-500"
)
.build();
apiController.getFilteredProductsAsync(getFilteredProductsInput);
client_controller = client.client
# Using a dictionary to pass parameters in Python
collect = {
'category': 'Electronics',
'price_range': '100-500'
}
client_controller.get_filtered_products(collect)
// Using an associative array in PHP
$collect = [
'category' => 'Electronics',
'price' => '100-500'
];
$client = ProductManagementApiClientBuilder::init()->build();
$client->getAPIController()->getFilteredProducts($collect);
ApiController apiController = client.ApiController;
// Using a Model to pass parameters in .NET
GetFilteredProductsInput getFilteredProductsInput = new GetFilteredProductsInput
{
Category = "Electronics",
Price = "100-500",
};
await apiController.GetFilteredProductsAsync(getFilteredProductsInput);
# Using a hash to pass parameters in Ruby
collect = {
'category' => 'Electronics',
'price_range' => '100-500'
}
client = ProductManagementApi::Client.new
client.client.get_filtered_products(collect)
apiController := client.ApiController()
ctx := context.Background()
// Using a struct to pass parameters in Go
collectedInput := productManagementApi.GetFilteredProductsInput{
Category: "Electronics",
Price: "100-500",
}
apiController.GetFilteredProducts(ctx, collectedInput)