olp-cpp-sdk  1.18.1
OlpClient.h
1 /*
2  * Copyright (C) 2019-2023 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <functional>
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include <olp/core/CoreApi.h>
29 #include <olp/core/client/CancellationContext.h>
30 #include <olp/core/client/OlpClientSettings.h>
31 
32 namespace olp {
33 namespace client {
39 class CORE_API OlpClient {
40  public:
42  using ParametersType = std::multimap<std::string, std::string>;
43 
45  using RequestBodyType = std::shared_ptr<std::vector<std::uint8_t>>;
46 
47  OlpClient();
48 
55  OlpClient(const OlpClientSettings& settings, std::string base_url);
56  virtual ~OlpClient();
57 
60 
63 
65  OlpClient(OlpClient&&) noexcept;
66 
68  OlpClient& operator=(OlpClient&&) noexcept;
69 
77  void SetBaseUrl(const std::string& base_url);
78 
84  std::string GetBaseUrl() const;
85 
93  ParametersType& GetMutableDefaultHeaders();
94 
108  void SetSettings(const OlpClientSettings& settings);
109 
129  CancellationToken CallApi(const std::string& path, const std::string& method,
130  const ParametersType& query_params,
131  const ParametersType& header_params,
132  const ParametersType& form_params,
133  const RequestBodyType& post_body,
134  const std::string& content_type,
135  const NetworkAsyncCallback& callback) const;
136 
157  HttpResponse CallApi(std::string path, std::string method,
158  ParametersType query_params,
159  ParametersType header_params, ParametersType form_params,
160  RequestBodyType post_body, std::string content_type,
161  CancellationContext context) const;
162 
182  HttpResponse CallApiStream(std::string path, std::string method,
183  ParametersType query_params,
184  ParametersType header_params,
185  http::Network::DataCallback data_callback,
186  RequestBodyType post_body,
187  std::string content_type,
188  CancellationContext context) const;
189 
190  private:
191  class OlpClientImpl;
192  std::shared_ptr<OlpClientImpl> impl_;
193 };
194 
195 } // namespace client
196 } // namespace olp
A wrapper that manages the cancellation state of an asynchronous operation in a thread-safe way.
Definition: CancellationContext.h:40
Cancels service requests.
Definition: CancellationToken.h:33
This class represents the HTTP response created from the NetworkResponse and the request body.
Definition: HttpResponse.h:89
Executes HTTP requests by using the base url and the provided parameters and body....
Definition: OlpClient.h:39
OlpClient(OlpClient &&) noexcept
A move constructor.
OlpClient & operator=(const OlpClient &)
An assignement operator.
std::shared_ptr< std::vector< std::uint8_t > > RequestBodyType
An alias for the HTTP request body.
Definition: OlpClient.h:45
OlpClient(const OlpClient &)
A copy constructor.
OlpClient(const OlpClientSettings &settings, std::string base_url)
Creates the OlpClient instance.
std::multimap< std::string, std::string > ParametersType
An alias for the parameters and headers type.
Definition: OlpClient.h:42
std::function< void(HttpResponse)> NetworkAsyncCallback
An alias for the asynchronous network callback.
Definition: OlpClientSettings.h:57
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
Configures the behavior of the OlpClient class.
Definition: OlpClientSettings.h:180