diff --git a/lib/api.hpp b/lib/api.hpp index cefcf00..afb48f0 100644 --- a/lib/api.hpp +++ b/lib/api.hpp @@ -13,22 +13,8 @@ using namespace std; class http_request; class http_response; - -class defapi { - public: - vector methods; - vector paths; - vector keys; - map> val_matrix; - - defapi(const vector _methods, const vector _paths, const vector _keys); - void necessary(const string _path, const vector _keys); -}; - class api { public: - defapi* def; - string method; string path; map params; @@ -36,11 +22,9 @@ class api { string body; // odlazni api zahtjev - api(defapi* _def, const string _method, const string _path, const map _params = {}, const string _body = {}); + api(const string _method, const string _path, const map _params = {}, const string _body = {}); // dolazni api zahjtev - api(defapi* _def, const http_request _req); - // bool validate(); - + api(const http_request _req); }; #endif diff --git a/lib/http.hpp b/lib/http.hpp index c051f80..56f02b5 100644 --- a/lib/http.hpp +++ b/lib/http.hpp @@ -9,8 +9,6 @@ using namespace std; - -class defapi; class api; class http_request { @@ -28,7 +26,6 @@ class http_request { //dolazni http_request(const string _raw); - //bool validate(); void putheader(const string _key, const string _value); void setheaders(const map _headers); void parse(); @@ -49,10 +46,6 @@ class http_response { void send(const string _body); // dolaznih void get(const string _raw); - - //bool validate(); - // void putheader(const string _key, const string _value); - // void putheaders(const map _headers); void mold(); // za slanje void parse(); // čitaj http diff --git a/src/api.cpp b/src/api.cpp index c6e4c2a..0d23575 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -1,17 +1,6 @@ #include "../lib/api.hpp" -defapi::defapi(const vector _methods, const vector _paths, const vector _keys) { - methods = _methods; - paths = _paths; - keys = _keys; -} - -void defapi::necessary(const string _path, const vector _keys) { - val_matrix[_path].insert( val_matrix[_path].end(), _keys.begin(), _keys.end()); -} - -api::api(defapi* _def, const string _method, const string _path, const map _params, const string _body) { - def = _def; +api::api(const string _method, const string _path, const map _params, const string _body) { method = _method; path = _path; url = path; @@ -26,13 +15,9 @@ api::api(defapi* _def, const string _method, const string _path, const mapval_matrix[path].size(); i++) { -// cout << def->val_matrix[path][i] << " " << params[def->val_matrix[path][i]] << endl; -// if (params[def->val_matrix[path][i]].empty()) { -// cout << "Ptazan " << endl; - -// isValidate = false; -// break; -// } -// } - -// return isValidate; -// } - +} \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp index 3933d46..74710d4 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -6,19 +6,11 @@ using namespace std; int main() { - defapi myApi({"GET"}, {"add", "delete", "update"}, {"id", "key", "value"}); - myApi.necessary("add", {"id", "key", "value"}); - myApi.necessary("delete", {"id"}); - myApi.necessary("update", {"id"}); - myApi.necessary("update", {"value"}); - try { - api uf(&myApi, "GET", "delete", {make_pair("id", "4")}, "bay"); + api uf("GET", "/delete", {make_pair("id", "4")}, "bay"); - } catch (string err) { - cout << err << endl; - } + // http myHttp(&myApi, "GET /fghfhf HTTP/1.1\r\nBaba"); // //http myHttp(&myApi, "GET /hello/?id=4&post=99 HTTP/1.1\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)\r\nHost: www.tutorialspoint.com\r\nAccept-Language: en-us\r\nAccept-Encoding: gzip, deflate\r\nConnection: Keep-Alive\r\n\r\nHELLO WORLD\r\n"); @@ -32,10 +24,10 @@ int main() { // cout << mojzahtjev.method << " " << mojzahtjev.url << endl << mojzahtjev.raw; - // http_request myres(&uf); - // myres.putheader("Content-type", "text/plain"); + http_request myres(&uf); + myres.putheader("Content-type", "text/plain"); - http_request myres("GET /delete?id=4 HTTP/1.1\r\nContent-type: text/plain\r\n\n\rBAY"); + // http_request myres(); // myres.get("HTTP/1.1 200 OK\r\n\r\nnotauth"); // myres.get("HTTP/1.1 200 OK"); @@ -43,11 +35,15 @@ int main() { // api uf(&myApi, myres); - // cout << uf.method << " " << uf.path << " " << uf.body << endl;// << myres.raw; - // cout << myres.method << " " << myres.url << " " << myres.body << endl;// << myres.raw; + cout << uf.method << " " << uf.path << " " << uf.body << endl; + cout << myres.method << " " << myres.url << " " << myres.body << endl << myres.raw << endl; // for(auto i : uf.params) // cout << i.first << " " << i.second << endl; + } catch (string err) { + cout << err << endl; + } + } diff --git a/test/test.o b/test/test.o index 4e9e762..dfe9922 100755 Binary files a/test/test.o and b/test/test.o differ