Delete API definition
This commit is contained in:
		
							parent
							
								
									3a7b5bd688
								
							
						
					
					
						commit
						4fdb494596
					
				
							
								
								
									
										20
									
								
								lib/api.hpp
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								lib/api.hpp
									
									
									
									
									
								
							| @ -13,22 +13,8 @@ using namespace std; | |||||||
| class http_request; | class http_request; | ||||||
| class http_response; | class http_response; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| class defapi { |  | ||||||
|     public: |  | ||||||
|     vector<string> methods; |  | ||||||
|     vector<string> paths; |  | ||||||
|     vector<string> keys; |  | ||||||
|     map<string, vector<string>> val_matrix; |  | ||||||
| 
 |  | ||||||
|     defapi(const vector<string> _methods, const vector<string> _paths, const vector<string> _keys); |  | ||||||
|     void necessary(const string _path, const vector<string> _keys); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| class api { | class api { | ||||||
|     public: |     public: | ||||||
|     defapi* def; |  | ||||||
| 
 |  | ||||||
|     string method; |     string method; | ||||||
|     string path; |     string path; | ||||||
|     map<string, string> params; |     map<string, string> params; | ||||||
| @ -36,11 +22,9 @@ class api { | |||||||
|     string body; |     string body; | ||||||
| 
 | 
 | ||||||
|     // odlazni api zahtjev
 |     // odlazni api zahtjev
 | ||||||
|     api(defapi* _def, const string _method, const string _path, const map<string, string> _params = {}, const string _body = {}); |     api(const string _method, const string _path, const map<string, string> _params = {}, const string _body = {}); | ||||||
|     // dolazni api zahjtev
 |     // dolazni api zahjtev
 | ||||||
|     api(defapi* _def, const http_request _req); |     api(const http_request _req); | ||||||
|     // bool validate();
 |  | ||||||
| 
 |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -9,8 +9,6 @@ | |||||||
| 
 | 
 | ||||||
| using namespace std; | using namespace std; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| class defapi; |  | ||||||
| class api; | class api; | ||||||
| 
 | 
 | ||||||
| class http_request { | class http_request { | ||||||
| @ -28,7 +26,6 @@ class http_request { | |||||||
|     //dolazni
 |     //dolazni
 | ||||||
|     http_request(const string _raw); |     http_request(const string _raw); | ||||||
| 
 | 
 | ||||||
|     //bool validate();
 |  | ||||||
|     void putheader(const string _key, const string _value); |     void putheader(const string _key, const string _value); | ||||||
|     void setheaders(const map<string, string> _headers); |     void setheaders(const map<string, string> _headers); | ||||||
|     void parse(); |     void parse(); | ||||||
| @ -50,10 +47,6 @@ class http_response { | |||||||
|     // dolaznih
 |     // dolaznih
 | ||||||
|     void get(const string _raw); |     void get(const string _raw); | ||||||
|      |      | ||||||
|     //bool validate();
 |  | ||||||
|     // void putheader(const string _key, const string _value);
 |  | ||||||
|     // void putheaders(const map<string, string> _headers);
 |  | ||||||
|      |  | ||||||
|     void mold();   // za slanje
 |     void mold();   // za slanje
 | ||||||
|     void parse();  // čitaj http
 |     void parse();  // čitaj http
 | ||||||
| }; | }; | ||||||
|  | |||||||
							
								
								
									
										42
									
								
								src/api.cpp
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								src/api.cpp
									
									
									
									
									
								
							| @ -1,17 +1,6 @@ | |||||||
| #include "../lib/api.hpp" | #include "../lib/api.hpp" | ||||||
| 
 | 
 | ||||||
| defapi::defapi(const vector<string> _methods, const vector<string> _paths, const vector<string> _keys) { | api::api(const string _method, const string _path, const map<string, string> _params, const string _body) { | ||||||
|     methods = _methods; |  | ||||||
|     paths = _paths; |  | ||||||
|     keys = _keys; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void defapi::necessary(const string _path, const vector<string> _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<string, string> _params, const string _body) { |  | ||||||
|     def = _def; |  | ||||||
|     method = _method; |     method = _method; | ||||||
|     path = _path;    |     path = _path;    | ||||||
|     url = path; |     url = path; | ||||||
| @ -26,13 +15,9 @@ api::api(defapi* _def, const string _method, const string _path, const map<strin | |||||||
| 
 | 
 | ||||||
|     body = _body; |     body = _body; | ||||||
| 
 | 
 | ||||||
|     // if (!validate()) {
 |  | ||||||
|     //     throw string("[ERROR] The API is not correct ");
 |  | ||||||
|     // }
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| api::api(defapi* _def, const http_request _req) { | api::api(const http_request _req) { | ||||||
|     def = _def; |  | ||||||
|     method = _req.method; |     method = _req.method; | ||||||
|     //path = _path;   
 |     //path = _path;   
 | ||||||
|     url = _req.url; |     url = _req.url; | ||||||
| @ -56,27 +41,4 @@ api::api(defapi* _def, const http_request _req) { | |||||||
| 
 | 
 | ||||||
|     body = _req.body; |     body = _req.body; | ||||||
| 
 | 
 | ||||||
|     // if (!validate()) {
 |  | ||||||
|     //     cout << "Nije ispravan API" << endl;
 |  | ||||||
|     // }
 |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| // bool api::validate() {
 |  | ||||||
| //     bool isValidate = true;
 |  | ||||||
| //     cout << "Validiramo " << endl;
 |  | ||||||
| //     // api validacija ključeva
 |  | ||||||
| //     for (uint i=0; i<def->val_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;
 |  | ||||||
| // }
 |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -6,19 +6,11 @@ using namespace std; | |||||||
| 
 | 
 | ||||||
| int main() { | 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 { |     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 /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");
 |     // //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;
 |     // cout << mojzahtjev.method << " " << mojzahtjev.url << endl << mojzahtjev.raw;
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     // http_request myres(&uf);
 |     http_request myres(&uf); | ||||||
|     // myres.putheader("Content-type", "text/plain");
 |     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\r\n\r\nnotauth");
 | ||||||
|     // myres.get("HTTP/1.1 200 OK");
 |     // myres.get("HTTP/1.1 200 OK");
 | ||||||
| @ -43,11 +35,15 @@ int main() { | |||||||
| 
 | 
 | ||||||
|     // api uf(&myApi, myres);
 |     // api uf(&myApi, myres);
 | ||||||
| 
 | 
 | ||||||
|     // cout << uf.method << " " << uf.path  << " " << uf.body << endl;// << myres.raw;
 |     cout << uf.method << " " << uf.path  << " " << uf.body << endl; | ||||||
|     // cout << myres.method << " " << myres.url  << " " << myres.body << endl;// << myres.raw;
 |     cout << myres.method << " " << myres.url  << " " << myres.body << endl << myres.raw << endl; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     // for(auto i : uf.params) 
 |     // for(auto i : uf.params) 
 | ||||||
|     //     cout << i.first << " " << i.second << endl;
 |     //     cout << i.first << " " << i.second << endl;
 | ||||||
| 
 | 
 | ||||||
|  |     } catch (string err) { | ||||||
|  |         cout << err << endl; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								test/test.o
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/test.o
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user