|
| 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