RIC-641 Fixing client/server model definitions and adding client and server API
[ric-plt/xapp-frame-cpp.git] / src / rest-client / RestClient.h
1 /*
2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
17 */
18 #ifndef _CPPREST_SDK_WRAPPER_H
19 #define _CPPREST_SDK_WRAPPER_H
20
21 #include<string>
22 #include<cpprest/http_client.h>
23 #include<cpprest/filestream.h>
24 #include<cpprest/uri.h>
25 #include<cpprest/json.h>
26 #include<sstream>
27 #include <cpprest/http_listener.h>
28 #include"nlohmann/json.hpp"
29 #include<functional>
30 #include"RestModel.h"
31 #include<thread>
32 #include <chrono>
33 #include <pthread.h>
34
35
36 namespace xapp
37 {
38         typedef struct resp
39         {
40                 long status_code;
41                 nlohmann::json body;
42                 //utility::string_t body;
43         }response_t;
44
45         typedef struct oran_resp
46         {
47                 long status_code;
48                 std::string SubscriptionId;
49         }oresponse_t;
50
51         class cpprestclient
52         {
53         protected:
54                 utility::string_t baseUrl;
55                 std::string Baseurl;
56                 //utility::string_t resp_url=U("http://0.0.0.0:8080/ric/v1/subscriptions/response");
57                 std::string resp_url = "http://0.0.0.0:8080/ric/v1/subscriptions/response";//default response url
58                 web::http::experimental::listener::http_listener listener;
59                 std::thread** t;
60                 void response_listener();
61                 bool ok_2_run;
62         public:
63                 void SetbaseUrl(std::string);
64                 std::string getBaseUrl();
65                 //O-RAN specific api calls
66                 oresponse_t post_subscriptions(const nlohmann::json & json, std::string path);
67                 int delete_subscriptions(std::string Id, std::string path);
68                 response_t get_subscriptions(std::string path);
69                 response_t get_config(std::string path);
70
71                 //general api calls
72                 virtual response_t do_get(std::string path);
73                 virtual response_t do_post(const nlohmann::json & json, std::string path);
74                 virtual response_t do_del(std::string Id, std::string path);
75                 //virtual response_t do_post(const web::json::value & json, std::string path);
76                 cpprestclient(std::string base_url, std::function<void(web::http::http_request)>callback);
77                 cpprestclient(std::string base_url,std::string response_url, std::function<void(web::http::http_request)>callback);
78                 cpprestclient(std::string base_url);
79                 virtual ~cpprestclient(){}
80                 //void start_response_listener();
81                 void stop_response_listener();
82         };
83
84 }
85
86
87
88
89
90 #endif