olp-cpp-sdk  1.21.0
NetworkRequest.h
1 /*
2  * Copyright (C) 2019-2020 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 <cstdint>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include <olp/core/CoreApi.h>
28 #include <olp/core/http/NetworkSettings.h>
29 
30 namespace olp {
31 namespace http {
32 
34 class CORE_API NetworkRequest final {
35  public:
37  using RequestBodyType = std::shared_ptr<const std::vector<std::uint8_t>>;
38 
40  enum class HttpVerb {
41  GET = 0,
42  POST = 1,
43  HEAD = 2,
44  PUT = 3,
45  DEL = 4,
46  PATCH = 5,
47  OPTIONS = 6,
48  };
49 
55  explicit NetworkRequest(std::string url);
56 
62  const Headers& GetHeaders() const;
63 
70 
79  NetworkRequest& WithHeader(std::string name, std::string value);
80 
86  const std::string& GetUrl() const;
87 
95  NetworkRequest& WithUrl(std::string url);
96 
102  HttpVerb GetVerb() const;
103 
112 
119 
129 
135  const NetworkSettings& GetSettings() const;
136 
145 
146  private:
148  HttpVerb verb_{HttpVerb::GET};
150  std::string url_;
152  Headers headers_;
154  RequestBodyType body_;
156  NetworkSettings settings_{};
157 };
158 
159 } // namespace http
160 } // namespace olp
A network request abstraction for an HTTP request.
Definition: NetworkRequest.h:34
const NetworkSettings & GetSettings() const
Gets the network settings for this request.
NetworkRequest & WithVerb(HttpVerb verb)
Sets the HTTP method.
Headers & GetMutableHeaders()
Gets the mutable reference to the HTTP headers.
NetworkRequest & WithSettings(NetworkSettings settings)
Sets network settings for this request.
HttpVerb GetVerb() const
Gets the HTTP method.
const Headers & GetHeaders() const
Gets all HTTP headers.
NetworkRequest & WithHeader(std::string name, std::string value)
Adds an extra HTTP header.
std::shared_ptr< const std::vector< std::uint8_t > > RequestBodyType
An alias for the HTTP request body.
Definition: NetworkRequest.h:37
NetworkRequest & WithBody(RequestBodyType body)
Sets the request body.
const std::string & GetUrl() const
Gets the request URL.
HttpVerb
The HTTP method, as specified at https://tools.ietf.org/html/rfc2616.
Definition: NetworkRequest.h:40
NetworkRequest(std::string url)
Creates the NetworkRequest instance.
RequestBodyType GetBody() const
Gets the request body.
NetworkRequest & WithUrl(std::string url)
Sets the request URL.
Contains a configuration for the network.
Definition: NetworkSettings.h:38
std::vector< Header > Headers
An alias for a vector of the HTTP headers.
Definition: NetworkTypes.h:140
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24