Skip to content

Commit 08d83f8

Browse files
authored
Instruction on how to work with unsupported APIs (#1172)
- Document how to work with generic Data APIs that are currently not supported by the Data SDK. - Add an example on how to download the difference between two versions of a catalog. - Change numbering and indentation in `docs/create-platform-client-settings.md` Relates-To: OLPEDGE-2488 Signed-off-by: Halyna Dumych <[email protected]>
1 parent 0d9351d commit 08d83f8

File tree

2 files changed

+84
-15
lines changed

2 files changed

+84
-15
lines changed

docs/create-platform-client-settings.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ You need to create the `OlpClientSettings` object to get catalog and partition m
4848
4949
5. (Optional) To configure a cache:
5050
51-
a. Create the `CacheSettings` instance with the cache that you want to enable and, if needed, the maximum cache size in bytes.
51+
1. Create the `CacheSettings` instance with the cache that you want to enable and, if needed, the maximum cache size in bytes.
5252
53-
> #### Note
54-
> By default, the downloaded data is cached in memory, and the maximum size of it is 1 MB.
53+
> #### Note
54+
> By default, the downloaded data is cached in memory, and the maximum size of it is 1 MB.
5555
56-
```cpp
57-
olp::cache::CacheSettings cache_settings;
58-
//On iOS, the path is relative to the Application Data folder.
59-
cache_settings.disk_path_mutable = "path to mutable cache";
60-
cache_settings.disk_path_protected = "path to protected cache";
61-
cache_settings.max_disk_storage = 1024ull * 1024ull * 32ull;
62-
```
56+
```cpp
57+
olp::cache::CacheSettings cache_settings;
58+
//On iOS, the path is relative to the Application Data folder.
59+
cache_settings.disk_path_mutable = "path to mutable cache";
60+
cache_settings.disk_path_protected = "path to protected cache";
61+
cache_settings.max_disk_storage = 1024ull * 1024ull * 32ull;
62+
```
6363
64-
b. Add the `CacheSettings` instance to the `DefaultCache` constructor.
64+
2. Add the `CacheSettings` instance to the `DefaultCache` constructor.
6565
66-
```cpp
67-
olp::client::OlpClientSettingsFactory::CreateDefaultCache(cache_settings);
68-
```
66+
```cpp
67+
olp::client::OlpClientSettingsFactory::CreateDefaultCache(cache_settings);
68+
```
6969
70-
To learn how to get or change cache size, see [Work with a cache](https://developer.here.com/documentation/sdk-cpp/dev_guide/docs/work-with-cache.html).
70+
To learn how to get or change cache size, see [Work with a cache](https://developer.here.com/documentation/sdk-cpp/dev_guide/docs/work-with-cache.html).
7171
7272
6. Set up the `OlpClientSettings` object, and if you want to add the expiration limit for the data that is stored in the cache, set the `default_cache_expiration` to the needed expiration time.
7373

docs/work-with-data-apis.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Work with unsupported Data REST APIs
2+
3+
HERE Data SDK for C++ supports only a limited number of Data REST APIs. You can find a list of them on our page with the [overall architecture](OverallArchitecture.md).
4+
5+
If you need to work with any Data REST APIs that are currently not supported, you can use the `olp::client::OlpClient` class from our core library for the request. It has an easy-to-use interface and a retry mechanism that uses a recommended backoff strategy for subsequent requests.
6+
7+
The example below demonstrates how to use the `olp::client::OlpClient` class from the Data SDK to call the API for downloading the difference between two versions of a versioned catalog.
8+
9+
**Example. Download the difference between two versions of a catalog.**
10+
11+
1. Create the `OlpClientSettings` object.
12+
13+
For instructions, see [Create platform client settings](create-platform-client-settings.md).
14+
15+
2. Configure an `OlpClient` instance in one of the following ways:
16+
- Use the `olp::client::ApiLookupClient` class to perform a request and get a preconfigured `olp::client::OlpClient` instance.
17+
- Use a base URL:
18+
1. Get the base URL from the lookup API service.
19+
20+
For instructions, see the [API Lookup API Developer's Guide](https://developer.here.com/documentation/api-lookup/dev_guide/index.html)
21+
22+
2. Create an `OlpClient` instance with the client settings from step 1 and the base URL.
23+
24+
```cpp
25+
olp::client OlpClient client(client_settings, base_url);
26+
```
27+
28+
3. Prepare the REST API request parameters and the metadata URL.
29+
30+
```cpp
31+
std::multimap<std::string, std::string> header_params;
32+
header_params.emplace("Accept", "application/json");
33+
34+
// Replace "my_layer" with the actual layer name.
35+
std::string metadata_url = "/layers/my_layer/changes";
36+
37+
std::multimap<std::string, std::string> query_params;
38+
39+
// Required parameters.
40+
query_params.emplace("startVersion", "0");
41+
query_params.emplace("endVersion", "1");
42+
43+
// Optional parameters.
44+
query_params.emplace("additionalFields", "dataSize,checksum");
45+
query_params.emplace("billingTag", "Billing1234");
46+
47+
// Can be used to cancel the ongoing request. Needs to be triggered
48+
// from another thread as `olp::client::OlpClient::CallApi()` is a blocking call.
49+
CancellationContext context;
50+
olp::client::HttpResponse response = client.CallApi(
51+
metadata_url, "GET", query_params, header_params, {}, nullptr, "", context);
52+
```
53+
54+
4. Check the response and, if needed, parse JSON.
55+
56+
```cpp
57+
if (response.GetStatus() != olp::http::HttpStatusCode::OK) {
58+
// If the response is not OK, handle error cases.
59+
}
60+
```
61+
62+
5. If the check passed and the status of the received `olp::client::HttpResponse` is `olp::http::HttpStatusCode::OK` (that is 200 OK), extract the encoded JSON from the response and parse it using RapidJSON or any other JSON parsing library.
63+
64+
```cpp
65+
std::string response_json;
66+
response.GetResponse(response_json);
67+
```
68+
69+
You get the information on the difference between the specified versions of the versioned catalog.

0 commit comments

Comments
 (0)