Requests with custom HTTP headers
- Last Updated: August 31, 2022
- 2 minute read
- DataDirect Connectors
- JDBC
- Autonomous REST Connector 6.0
- Documentation
Custom HTTP headers can be used to filter requests or specify a value for the Accept header.
Some endpoints employ custom HTTP headers to filter data returned by a GET or POST request. This type of filtering is typically used to create multiple unique reports/tables from the same endpoint. To use custom headers, you must define the request in the Model file. The Model file entry is comprised of a path and header object. The path object contains the URL endpoint used in requests, while the header object defines the headers and provides value arguments used to filter the request.
- If a service returns responses in multiple supported formats (JSON, XLM, CSV). By
default, the driver attempts to use JSON format when multiple formats are available;
however, if you prefer, you can specify a different format using the Accept header. For
example, to specify the XML format:
"#headers":{ "Accept": "application/xml" } - If the default Accept header,
application/json, is not accepted by the endpoint. This scenario typically occurs when accessing a vendor endpoint that uses a proprietary Accept header.
An entry for a GET request using custom HTTP headers takes the following form for an entry that defines three headers. You can define one or more headers in an entry.
"<table_name>":{
"#path": "<host_name>/<endpoint_path>",
"#headers":{
"<header1>":"<value1>",
"<header2>":"<value2>",
"<header3>":"<value3>"
}
}
- table_name
- is the name of the relational table to which the driver maps the endpoint. For example, people.
- host_name
- (optional) is the protocol and host name components of the URL endpoint. For example, http://example.com. You can omit this value by specifying the host name using the ServerName property.
- endpoint_path
- is the path component of the URL endpoint. For example,
times. This can be an unparameterized or parameterized path, a path that uses query parameters, or an array of paths. See "Query paths" for examples and more information. - header
- is the HTTP header component of the
header=valuepair used for filtering the request. For example,X-Subway-Payment.When overriding the Accept header, this value is
Accept. - value
- is the value argument for the HTTP header used for filtering the
request or, if overriding the default Accept header, the value of the Accept header for
the endpoint. For example,
token.
For example, the following demonstrates an entry for a GET request that defines custom HTTP headers.
"people":{
"#path": "http://example.com/people",
"#headers":{
"Accept":"application/calendar+json",
"X-Subway-Payment":"token",
"X-Laundry-Service":"dryclean",
"X-Favorite-Food":"pizza"
}
},