# DeviceAtlas Cloud Client API Configuration #
This section deals with configuring the DeviceAtlas Cloud API.
The DeviceAtlas Cloud Client API is configured via setter methods at runtime.
The only required setting is your DeviceAtlas licence key.
The API provides a number of cache providers and each has a configuration file
located in the Api/config directory. The configuration file for the selected
cache provider must be available on the classpath.
### Caching ###
The API can cache the returned data after a call to the DeviceAtlas Cloud service,
this will speed up subsequent requests.
The API uses the built in .NET cache as much as possible. The .NET cache in
versions before .NET 4 is memory based and gets cleared each time the application
is restarted. To help with this the DeviceAtlas Cloud Client can also cache data
in files to backup the memory cache.
The file cache stores the returned properties on your server disk. The cache
location is typically the system temp directory but this can be overridden with
the settings. Items in the cache expire after a set time period to ensure the
data is up-to-date. This cache is enabled by default. It is recommended to
always have file caching enabled.
### Client Side Component ###
In addition to the properties from the data file, properties can be gathered from
the client's browser and used both on the client side and on the server side.
It is strongly recommended to use the Client-side component when using the DeviceAtlas
Cloud API within a web application in order to correctly identify iOS devices.
The client side resource (https://cs-cdn.deviceatlas.com/dacs.js)
must be included on your webpage in order for it to detect the client side properties.
The contents of this cookie are automatically detected by the API.
Please click [here](https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html) for
more information.
#### Usage with Client Side Component ####
In addition to normal usage, DeviceAtlas has the capability to capture client
side properties and merge them into the server side properties.
The "deviceatlas.min.js" file must be included on your webpage in order for it
to detect the client side properties. The contents of this cookie are
automatically detected with the request headers. Both sets of properties are
used in additional logic to determine other properties such iPhone and iPad
models which are normally not detectable.
By default, if the cookie exists it will be used by the API. To disable using
the client side cookie:
```csharp
client.SetUseClientCookie(false);
```
### DeviceAtlas Cloud Service End-points ###
The DeviceAtlas Cloud Service is powered by independent clusters of servers
spread around the world. This ensures optimum speed and reliability. The API is
able to automatically switch to a different end-point if the current end-point
becomes unavailable. It can also (optionally) auto-rank all of the service
end-points to choose the end-point with the lowest latency for your location.
Cloud service provider servers are defined as an array of "Server" objects.
Class "Server" exists in the "mobi.mtld.deviceatlas.cloud" package.
A default Server array is built in the API but you can manually set:
```csharp
Server[] servers = {
new Server("SERVER-HOST-ADDRESS", SERVER-PORT),
new Server("SERVER-HOST-ADDRESS", SERVER-PORT)
};
client = Client.GetInstance();
client.SetServers(servers);
```
By default the API will analyze the end-points from time to time to rank them by
their stability and response speed. The ranked list is then cached and used
whenever the Client API needs to query the DeviceAtlas Cloud Service. If an end-
point fails, the Client API will automatically switch to the next end-point on
the list.
There is no need to set the servers array if auto-ranking is turned on. If you
wish, you may re-order the array and turn auto-ranking off. In this case the API
will respect your preferred order of end-points and only switch to a different
end-point should the primary one fail to resolve.
#### Notes ####
* With the default auto-ranking settings, the ranking is done every 24 hours.
The actual time may be more than 24 hours as the ranking is only triggered by
a request to the Client API and the cached server list is older than value set
by client.SetAutoServerRankListLifetime(1440).
* During end-point analysis a number of requests are made to each end-point.
Please note that these requests count towards your total hits to
the Cloud service.
e.g:
```csharp
if
Server list contains 3 servers
AUTO SERVER RANKING LIFETIME = 1440
AUTO SERVER RANKING NUM REQUESTS = 3
then
auto ranking will add 9 (3x3) hits per day
```
#### Methods ####
* Get the ranked server list:
```csharp
Server[] rankedServerList = client.GetServers();
```
The first end-point in the list will be used to make a request to the cloud, if
it fails the next end-point will be take it's place.
* Get the end-point used for the last request:
```csharp
Server server = client.GetCloudUrl();
```
Note that if the data comes from cache this method will return "null".
* Get end-point info. This is useful when you want to manually rank the server list:
```csharp
Server[] server = client.GetServersLatencies();
```
Please see https://deviceatlas.com/resources/cloud-service-end-points for more
information.
#### Cloud Server end-point settings ####
##### client.SetAutoServerRanking(true) #####
To turn auto ranking on/off. To manually rank the servers set to "false"
and edit the SERVERS list to set your preferred order of end-points.
The API will not rank the servers and will use the SERVERS list items
directly with the topmost server used first to get device data. On fail-
over the next end-point in the list will be used.
##### client.SetCloudServiceTimeout(2) #####
Time in seconds. If an end-point fails to respond in this amount of time
the API will fail-over to the next end-point on the list.
##### client.SetAutoServerRankingMaxFailures(1) #####
When auto ranking servers, if a server fails more than this number of
times it will not be included in the list.
##### client.SetAutoServerRankingNumRequests(3) #####
When auto ranking servers, number of requests to perform for service
speed calculation.
##### client.SetAutoServerRankListLifetime(1440) #####
Time in minutes. How often to auto rank servers.
0 = servers will be ranked and cached only once and this list will not
be updated automatically. You can update this list manually:
DeviceAtlasCloudClient.RankServers();
Note: AUTO SERVER RANKING must be set to true so this cached server list
will be used by the API even if AUTO SERVER RANKING LIFETIME is set to 0
Note: If AUTO SERVER RANKING = false then the cached server list will be
totally ignored.
##### client.SetServerPhaseOutLifetime(1440) #####
Used when auto ranking is OFF. Specifies how long to use the fail-over
endpoints before the preferred end-point is re-checked. If the preferred
end-point is available it will be added back into the list of end-points
and used for future requests.
### Extra Tools ###
This package comes with extra tools that can help you enhance your mobile websites.
#### DeviceAtlas Client Side Component ####
This is the DeviceAtlas Client Side component which discovers device info on
client side to augment the server data.
This library is used in the DeviceAtlas Cloud Client API examples.
#### Latency Checker ####
There are two command line tools included in this package to help you tweak the
DeviceAtlas Cloud API end-point selecting.
##### Check Server Latency #####
This tool can be used to get info about the DeviceAtlas Cloud Service end-points.
The info shown can be used for manually setting up the DeviceAtlas Clous service
end-points in the API. To access the cloud servers a valid DeviceAtlas licence
would be required.
Usage (command line):
```csharp
\path\to\ExtraTools\LatencyChecker\CheckServerLatency.exe LICENCE-KEY
```
##### Update Server Ranking Cache #####
When AUTO_RANKING is set ON you can use this tool to re rank the DeviceAtlas Cloud
end-points. All you need to do is to run this script in regular intervals which
are smaller than the "AUTO_SERVER_RANKING_LIFETIME".
Usage (command line):
```csharp
\path\to\ExtraTools\LatencyChecker\UpdateServerRankingCache.exe LICENCE-KEY
```
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _
_ https://deviceatlas.com _