NUGU SDK Linux  1.7.6
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 #include <nugu.h>
25 
26 namespace NuguClientKit {
27 
42 class NUGU_API NuguHttpRest {
43 public:
44  explicit NuguHttpRest(const std::string& url);
45  virtual ~NuguHttpRest();
46 
50  typedef std::function<void(const NuguHttpResponse* resp)> ResponseCallback;
51 
56  void setTimeout(long msecs);
57 
62  void setConnectionTimeout(long msecs);
63 
68  std::string getUrl();
69 
78  bool addHeader(const std::string& key, const std::string& value);
79 
87  bool removeHeader(const std::string& key);
88 
94  std::string findHeader(const std::string& key);
95 
103  NuguHttpResponse* get(const std::string& path,
104  const NuguHttpHeader* additional_header = nullptr);
105 
114  bool get(const std::string& path, ResponseCallback cb);
115 
125  bool get(const std::string& path,
126  const NuguHttpHeader* additional_header, ResponseCallback cb);
127 
136  NuguHttpResponse* post(const std::string& path, const std::string& body,
137  const NuguHttpHeader* additional_header = nullptr);
138 
148  bool post(const std::string& path, const std::string& body, ResponseCallback cb);
149 
160  bool post(const std::string& path, const std::string& body,
161  const NuguHttpHeader* additional_header, ResponseCallback cb);
162 
171  NuguHttpResponse* put(const std::string& path, const std::string& body,
172  const NuguHttpHeader* additional_header = nullptr);
173 
183  bool put(const std::string& path, const std::string& body, ResponseCallback cb);
184 
195  bool put(const std::string& path, const std::string& body,
196  const NuguHttpHeader* additional_header, ResponseCallback cb);
197 
205  NuguHttpResponse* del(const std::string& path,
206  const NuguHttpHeader* additional_header = nullptr);
207 
216  bool del(const std::string& path, ResponseCallback cb);
217 
227  bool del(const std::string& path,
228  const NuguHttpHeader* additional_header, ResponseCallback cb);
229 
230 private:
231  static int response_callback(NuguHttpRequest* req,
232  const NuguHttpResponse* resp, void* user_data);
233 
234  NuguHttpHost* host;
235  NuguHttpHeader* common_header;
236  struct pending_async_data {
237  ResponseCallback cb;
238  };
239 };
240 
245 } // NuguClientKit
246 
247 #endif /* __NUGU_HTTP_REST_H__ */
NUGU HTTP Rest.
Definition: nugu_http_rest.hh:42
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:50
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:46
struct _nugu_http_request NuguHttpRequest
HTTP Request object.
Definition: nugu_http.h:51
struct _nugu_http_host NuguHttpHost
HTTP Host object.
Definition: nugu_http.h:41
HTTP Response object.
Definition: nugu_http.h:72