NUGU SDK Linux  1.7.5
nugu_http_rest.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 SK Telecom Co., Ltd. All rights reserved.
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 
17 #ifndef __NUGU_HTTP_REST_H__
18 #define __NUGU_HTTP_REST_H__
19 
20 #include <functional>
21 #include <string>
22 
23 #include <base/nugu_http.h>
24 
25 namespace NuguClientKit {
26 
41 class NuguHttpRest {
42 public:
43  explicit NuguHttpRest(const std::string& url);
44  virtual ~NuguHttpRest();
45 
49  typedef std::function<void(const NuguHttpResponse* resp)> ResponseCallback;
50 
55  void setTimeout(long msecs);
56 
61  void setConnectionTimeout(long msecs);
62 
67  std::string getUrl();
68 
77  bool addHeader(const std::string& key, const std::string& value);
78 
86  bool removeHeader(const std::string& key);
87 
93  std::string findHeader(const std::string& key);
94 
102  NuguHttpResponse* get(const std::string& path,
103  const NuguHttpHeader* additional_header = nullptr);
104 
113  bool get(const std::string& path, ResponseCallback cb);
114 
124  bool get(const std::string& path,
125  const NuguHttpHeader* additional_header, ResponseCallback cb);
126 
135  NuguHttpResponse* post(const std::string& path, const std::string& body,
136  const NuguHttpHeader* additional_header = nullptr);
137 
147  bool post(const std::string& path, const std::string& body, ResponseCallback cb);
148 
159  bool post(const std::string& path, const std::string& body,
160  const NuguHttpHeader* additional_header, ResponseCallback cb);
161 
170  NuguHttpResponse* put(const std::string& path, const std::string& body,
171  const NuguHttpHeader* additional_header = nullptr);
172 
182  bool put(const std::string& path, const std::string& body, ResponseCallback cb);
183 
194  bool put(const std::string& path, const std::string& body,
195  const NuguHttpHeader* additional_header, ResponseCallback cb);
196 
204  NuguHttpResponse* del(const std::string& path,
205  const NuguHttpHeader* additional_header = nullptr);
206 
215  bool del(const std::string& path, ResponseCallback cb);
216 
226  bool del(const std::string& path,
227  const NuguHttpHeader* additional_header, ResponseCallback cb);
228 
229 private:
230  static int response_callback(NuguHttpRequest* req,
231  const NuguHttpResponse* resp, void* user_data);
232 
233  NuguHttpHost* host;
234  NuguHttpHeader* common_header;
235  struct pending_async_data {
236  ResponseCallback cb;
237  };
238 };
239 
244 } // NuguClientKit
245 
246 #endif /* __NUGU_HTTP_REST_H__ */
NUGU HTTP Rest.
Definition: nugu_http_rest.hh:41
bool get(const std::string &path, const NuguHttpHeader *additional_header, ResponseCallback cb)
HTTP GET async requests.
bool removeHeader(const std::string &key)
Remove a key-value from common header.
NuguHttpResponse * post(const std::string &path, const std::string &body, const NuguHttpHeader *additional_header=nullptr)
HTTP POST requests.
NuguHttpResponse * del(const std::string &path, const NuguHttpHeader *additional_header=nullptr)
HTTP DELETE requests.
bool put(const std::string &path, const std::string &body, ResponseCallback cb)
HTTP PUT async requests.
bool del(const std::string &path, ResponseCallback cb)
HTTP DELETE async requests.
bool post(const std::string &path, const std::string &body, const NuguHttpHeader *additional_header, ResponseCallback cb)
HTTP POST async requests.
bool del(const std::string &path, const NuguHttpHeader *additional_header, ResponseCallback cb)
HTTP DELETE async requests.
std::function< void(const NuguHttpResponse *resp)> ResponseCallback
Callback prototype for receiving async response.
Definition: nugu_http_rest.hh:49
bool get(const std::string &path, ResponseCallback cb)
HTTP GET async requests.
NuguHttpResponse * put(const std::string &path, const std::string &body, const NuguHttpHeader *additional_header=nullptr)
HTTP PUT requests.
void setTimeout(long msecs)
Set timeout to host.
bool put(const std::string &path, const std::string &body, const NuguHttpHeader *additional_header, ResponseCallback cb)
HTTP PUT async requests.
NuguHttpResponse * get(const std::string &path, const NuguHttpHeader *additional_header=nullptr)
HTTP GET requests.
bool addHeader(const std::string &key, const std::string &value)
Add a key-value string to common header.
std::string getUrl()
Get the url of host.
bool post(const std::string &path, const std::string &body, ResponseCallback cb)
HTTP POST async requests.
void setConnectionTimeout(long msecs)
Set connection timeout to host.
std::string findHeader(const std::string &key)
Find a value for key from common header.
struct _nugu_http_header NuguHttpHeader
HTTP Header object.
Definition: nugu_http.h:45
struct _nugu_http_request NuguHttpRequest
HTTP Request object.
Definition: nugu_http.h:50
struct _nugu_http_host NuguHttpHost
HTTP Host object.
Definition: nugu_http.h:40
HTTP Response object.
Definition: nugu_http.h:71