Configure API
Quick start
Here is a basic YAML file that is configured to retrieve the weather forecast for London, UK from Open-Meteo.com.
version: 1 shares: - share-name: "weather" file-name: "london-temps.json" target-api: method: GET scheme: https host: api.open-meteo.com port: 443 path: v1/forecast?latitude=51.52&longitude=0.127&hourly=temperature_2m headers: accept: application/json
The weather data will be accessible from the following path \\server_name\weather\london-temps.json.
The detail
The apis.yaml file has a simple structure.
version: 1 shares: - One or more unc share objects
Each configured UNC Share object must have a corresponding license, otherwise Api2File will halt to allow the correct number of UNC shares to be configured in the `apis.yaml` file.
Each UNC Share represents a root level share that is made available to network clients to interact with an API.
Schema
In the following description, if a field is not explicitly REQUIRED or described with a MUST or SHALL, it can be considered OPTIONAL.
Root Object
Field Name | Type | Description |
---|---|---|
version | string | REQUIRED. Must be the value 1. |
shares | [Share Object] | REQUIRED. List of endpoints to expose via the UNC share. |
Shares
Defines one or more UNC shares to be exposed to network clients.
Field Name | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
share-name | string | REQUIRED. Names the share and is used as the root path share name when clients are accessing the data via a file-browser. | ||||||||
file-name | string | REQUIRED. Defines the name to be given to downloadable files within the unc share. Use the Example:
Example file-name values with share outcome:
Supports braces Example: Using variables in file-name
version: 1.0 shares: - share-name: share-name file-name: "{{dog}}\\{{colour}}.txt" target-api: ... variables: - name: colour type: enum options: - Red - Blue - Green - name: dog type: enum options: - Lab - Pug In the example above, 6 files will be made available, within a hierarchy of two directories. \\server\share-name\Lab\Red.txt \\server\share-name\Lab\Blue.txt \\server\share-name\Lab\Green.txt \\server\share-name\Pug\Red.txt \\server\share-name\Pug\Blue.txt \\server\share-name\Pug\Green.txt | ||||||||
variables | [Variable Object] | List of variables used to traverse an APIs endpoints and discover data. | ||||||||
target-api | Target Object | REQUIRED. The Target APIs. These specify information about the data source API that enables Api2File to discover and connect to it. | ||||||||
transform | [Transform Line Object] | List of Transform lines. These lines specify how the data retrieved from the API will be transformed before being exposed as a file. | ||||||||
cache-override | Cache override Object | Share specific cache functionality overrides. These allow the API specified cache settings (supplied via the response headers) to be overridden. |
Variables
Defines one or more variables to be used when constructing the data path.
Field Name | Type | Description |
---|---|---|
name | string | REQUIRED. Names the variable within the path template. |
type | string | REQUIRED. The type of the variable. MUST be one of enum, dynamic. |
options | [string] | When paired with type=enum, contains a list of the accepted enumeration values for the variable. |
dynamic-uri | string | Path, relative to the API being called, to retrieve data for the variable. |
dynamic-path | template string | A template that yields one or more |
Target API
Defines connectivity options for the API that will be the source of the data.
Field Name | Type | Description |
---|---|---|
method | string | REQUIRED. Specifies the HTTP Method. MUST be one of GET, POST, PUT. |
scheme | string | REQUIRED. The request scheme to use. MUST be one of http, https. |
host | string | REQUIRED. The host name or IP of the API. |
port | number | REQUIRED. The port to access the API. |
path | template string | REQUIRED. The path to the API data to retrieve. Supports braces Example: Using variables in Path
version: 1.0 shares: - share-name: share-name file-name: "{{colour}}.txt" target-api: ... path: v1/{{colour}}/data variables: - name: colour type: enum options: - Red - Orange - Pink
In this example, the variable {{colour}} in the filename will be used in the API request path. For the file
|
headers | Headers Object | Describes any additional HTTP headers that must be sent to the API during the request for data. |
content-type-override | string | If specified, treats the API response as being the defined content type. Useful when the API doesn't correctly set the content-type header in its response. |
default-user-auth | Default User Auth Object | Describes the fallback API authentication to use when the user accessing the UNC share isn't covered by any user-auth defined rules. |
user-auth | Map of <user id, User Auth Object> |
Describes the set of rules for providing differing authentication credentials to the API dependent on the accessing UNC client.
User id is a string that is matched against the client accessing the UNC share. Taking the form domain\user or user. |
Headers
Allows HTTP headers to be sent to the API as part of the request for data.
The Headers object is a map of header name to static or dynamic data. A template string allows use of fixed text or dynamic information in generating the field value.
headers: accept: application/json x-custom-header: myHeaderValue
Although it is possible to pass authentication data using the headers property, it is recommended that the user-auth and default-user-auth objects are used for this purpose.
Braces {{}} variable substitution can be used in headers. The value of the variable set will correspond to the variables utilised to build the selected file path.
version: 1.0 shares: - share-name: share-name file-name: "{{colour}}.txt" target-api: method: GET scheme: https host: www.example.com port: 443 path: v1/data headers: accept: text/plain x-custom-color: {{colour}} variables: - name: colour type: enum options: - Red - Blue - Green - Orange - Pink
In this example, the variable {{colour}} in the filename will be delivered to the API in the x-custom-color
HTTP header. For the file
\\server\share-name\Orange.txt
the header will be populated with the value Orange
.
User Authentication
Defines users or groups of users and the manner in which they are authorised to interact with the API data on the UNC shares.
The value of the key for each sub object under the user-auth:
section is the local domain\user
for whom the API credentials will apply.
Omitting the domain\
will match the username across all local domains. More fine-grained control over domain and username matching can be achieved using wildcard characters.
Field Name | Type | Description |
---|---|---|
deny | boolean | Default: false. If set, specifies the user's access to the UNC share. Set to false to allow access, true to refuse access. If omitted, the user is by-default allowed. |
type | string |
Defines the authentication type to be applied when a user matching the map accesses API data. If set, MUST be one of
none,
basic,
apikey,
bearer,
oauth2,
jwt. Aside from 'none', a corresponding authentication object MUST be populated in the same user-auth block. |
basic | Basic Auth Object | Describes basic authentication properties to supply with the API request. |
apikey | ApiKey Auth Object | Describes ApiKey authentication properties to supply with the API request. |
bearer | Bearer Auth Object | Describes Bearer authentication properties to supply with the API request. |
oauth2 | Oauth2 Auth Object | Describes Oauth2 authentication properties to supply with the API request. |
Basic Authentication Object
Defines properties of the Basic authentication headers that are delivered to the API.
Field Name | Type | Description |
---|---|---|
username | string | REQUIRED. Defines the username. |
password | string | REQUIRED. Defines the password. |
ApiKey Authentication Object
Defines properties of the ApiKey authentication headers that are delivered to the API.
Field Name | Type | Description |
---|---|---|
in | string | REQUIRED. Defines the where the API key is presented to the API. MUST be one of header, query. |
name | string | REQUIRED. Defines the name of the header or query parameter that delivers the API key. |
apikey | string | REQUIRED. Defines the value of the API key. |
This example specifies the value for an API delivered in the HTTP headers called x-apiKey.
type: apikey apikey: in: header name: x-apikey apikey: 1234-abcd-7890
Bearer Authentication Object
Defines properties of the Bearer authentication headers that are delivered to the API.
Field Name | Type | Description |
---|---|---|
token | string | REQUIRED. Defines the token value to supply within the Authorization: bearer header. |
Oauth2 Authentication Object
Defines properties of the Oauth2 authentication headers that are delivered to the API.
A standardised Oauth2 authentication call will be made to the defined token endpoint. Any generated tokens are only used once and new tokens will be generated for any subsequent requests to the API.
Api2File is not compatible with Non-Oauth2-compliant token issuers and currently there is no way to manually generate a token for future use. Pre-generated long-lived tokens can be delivered using the bearer-auth authentication type.
Field Name | Type | Description |
---|---|---|
clientid | string | REQUIRED. Defines the clientId value that will be used when generating an Oauth2 token. |
clientsecret | string | REQUIRED. Defines the clientsecret value that will be used when generating an Oauth2 token. |
tokenurl | string | REQUIRED. Defines the url of the token issuer. |
Line Transform
Defines the structure of the file to be delivered to the UNC client based on the API data. Utilises .net Razor templates.
Field Name | Type | Description |
---|---|---|
line | template string | REQUIRED. Defines one or more text lines to be transformed into the output file. |
This example builds the CSV file from the json content supplied by the API. The file contains a fixed header row, then the values of the 'items' property of the json payload.
transform: - line: "COLUMN,VALUE" - line: | @foreach(var bodyItem in Model.Content.GetItems("$.items.[::1]")){ <text>body,@(bodyItem.GetValue(""))@(System.Environment.NewLine)<text> }
Each line template can utilise several built-in functions to access data from the API response. The content is automatically parsed based on the Content-Type header provided by the API. Supported values include application/json and application/xml.
For more information see the Template documentation.
Cache Override
Allows overriding of API defined cache settings. Normally the response header Cache-Control will be parsed and the rules it contains applied to the data caching, however supplying overrides in the cache-override section allows these headers to be overridden.
Field Name | Type | Description |
---|---|---|
disable-cache | boolean | Defines if all response data caching should be disabled for the share. Setting this to true is the same as the API setting the cache-control: no-store; header. |
max-age | integer | Defines the maximum age (in seconds) of the cached data. If data contained in the cache is older, it will be re-retrieved from the API. This overrides the Cache-Control: max-age=x; header set by the API. |