API parameters
The way that API requests and responses behave is greatly influenced by parameters. In this article, we will explore the different types of parameters, their usage, and how they can be employed in the Custom Connector interface.
Custom Connector supports several types of parameters, each serving a distinct purpose. Understanding these parameter types is key to effectively configuring your API requests.
Query parameter
Query parameters are attached to the end of the URI and are used to modify the API request. Query parameters are typically appended to the URI by adding a question mark (?) followed by key-value pairs separated by ampersands (&).
For example: https://api.exchangeratesapi.io/latest?symbols=USD,GBP,INR&base=USD
Here, symbols
and base
are query parameters influencing the API response.
URI parameter
URI parameters are elements within the path of the endpoint URI itself, placed before the query string (if present). These parameters are often enclosed in curly brackets ({}) and can be replaced with specific values.
For example: https://api.exchangeratesapi.io/{date-in}?symbols=USD,GBP,INR&base=USD
In this example, {date-in}
is a URI parameter, and it can be replaced with a specific date value to retrieve exchange rates for that date.
Header parameter
A header parameter is a type of parameter in an API request that is included in the request header. Unlike query parameters that are appended to the end of the URI or path parameters that are part of the endpoint's URL path, header parameters are included in the HTTP headers of the request. They are typically used to provide additional information or metadata to the server.
Here's a detailed explanation of header parameters with an example using the Open Exchange Rates API:
Example API Request:
Suppose you want to retrieve exchange rates for specific currencies from the Open Exchange Rates API for a particular date. The API endpoint you're interested in is: https://api.exchangeratesapi.io/{date-in}?symbols=USD,GBP,INR&base=USD
In this example, we'll focus on the base currency and how it can be specified using a header parameter.
Header parameter usage:
To specify the base currency in the API request using a header parameter, you would typically include a header named Base-Currency (or any other relevant name) in the HTTP request header. The value of this header would be the currency code you want to use as the base currency.
Here's how you can use a header parameter in this scenario:
- Create the header parameter: Define a header parameter named
Base-Currency
in this example API request configuration. - Set the header value: In this case, you want the base currency to be
USD
, so you set the value of theBase-Currency
header toUSD
. - Include the header in the request: When you make the API request, the HTTP request header will include the
Base-Currency
header with the valueUSD
.
API Request with Header parameter
GET https://api.exchangeratesapi.io/{date-in}?symbols=USD,GBP,INR
Headers:
- Base-Currency: USD
In this request, the Base-Currency
header is used to specify that you want the exchange rates to be provided with USD
as the base currency. The server will process the request based on this header information and return the exchange rates accordingly.
Header parameters are often used for information that doesn't belong in the URI or query parameters. They are suitable for metadata, authentication tokens, or any data that should be included in the header for various reasons, such as security, API versioning, or custom requirements.