Skip to content

Commit ca86d44

Browse files
committed
feat:health rest apis & updated docs
feat:getHealth, getAntivirus, getDB, getCache, getPubSub
1 parent dbeee5d commit ca86d44

File tree

14 files changed

+183
-3
lines changed

14 files changed

+183
-3
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ getFileDownload: $(SRCS) $(EXAMPLES_DIR)/storage/files/getFileDownload.cpp
127127
# Health
128128
getHealth: $(SRCS) $(EXAMPLES_DIR)/health/getHealth.cpp
129129
$(CXX) $(CXXFLAGS) -o tests/health/getHealth $(SRCS) $(EXAMPLES_DIR)/health/getHealth.cpp $(LDFLAGS)
130+
getAntivirus: $(SRCS) $(EXAMPLES_DIR)/health/getAntivirus.cpp
131+
$(CXX) $(CXXFLAGS) -o tests/health/getAntivirus $(SRCS) $(EXAMPLES_DIR)/health/getAntivirus.cpp $(LDFLAGS)
132+
getCache: $(SRCS) $(EXAMPLES_DIR)/health/getCache.cpp
133+
$(CXX) $(CXXFLAGS) -o tests/health/getCache $(SRCS) $(EXAMPLES_DIR)/health/getCache.cpp $(LDFLAGS)
134+
getDB: $(SRCS) $(EXAMPLES_DIR)/health/getDB.cpp
135+
$(CXX) $(CXXFLAGS) -o tests/health/getDB $(SRCS) $(EXAMPLES_DIR)/health/getDB.cpp $(LDFLAGS)
136+
getPubSub: $(SRCS) $(EXAMPLES_DIR)/health/getPubSub.cpp
137+
$(CXX) $(CXXFLAGS) -o tests/health/getPubSub $(SRCS) $(EXAMPLES_DIR)/health/getPubSub.cpp $(LDFLAGS)
130138

131139
clean:
132140
rm -f tests/*

docs/Health.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Class: Health
2+
Works around with Health Checks in Appwrite
3+
4+
### Core
5+
6+
| Method Name | Usage | Link |
7+
|-------------|------------------------------------------------------------------------------------------------|--------------------------------------------------------|
8+
| `getHeath()` | Gets HTTP health in the Appwrite project. | [Example](/examples/health/getHealth.cpp) |
9+
| `getAntivirus()` | Fetches the antivirus status from the Appwrite project | [Example](/examples/health/getAntivirus.cpp) |
10+
| `getCache()` | Fetches the cache status in the Appwrite project. | [Example](/examples/health/getCache.cpp) |
11+
| `getDB()` | Fetches the DB in the Appwrite project. | [Example](/examples/health/getDB.cpp) |
12+
| `getPubSub()` | Fetches the PubSub status in the Appwrite project. | [Example](/examples/health/getPubSub.cpp) |

docs/Storage.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Works around with Storage Buckets and files in Appwrite
1515

1616
| Method Name | Usage | Link |
1717
|-------------|------------------------------------------------------------------------------------------------|--------------------------------------------------------|
18-
| `createFile()` | Creates a new File in the Bucket in the Appwrite project. | [Example](/examples/storage/files/createFile.cpp) |
1918
| `getFile()` | Fetches the file from the bucket in the Appwrite project using the unique bucket ID. | [Example](/examples/storage/files/getFile.cpp) |
2019
| `getFileView()` | Fetches the file from the bucket in the Appwrite project using the unique bucket ID. | [Example](/examples/storage/files/getFileView.cpp) |
2120
| `getFileDownload()` | Retrieves a file buffer for download from the buckets in the Appwrite project. | [Example](/examples/storage/files/getFileDownload.cpp) |

examples/health/getAntivirus.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
4+
int main() {
5+
std::string projectId = "66fbb5a100070a3a1d19";
6+
std::string apiKey = "";
7+
8+
Appwrite appwrite(projectId);
9+
Health& health = appwrite.getHealth();
10+
11+
health.setup(apiKey, projectId);
12+
13+
try {
14+
std::string response = health.getAntivirus();
15+
std::cout << "Health Check Done! \nResponse: " << response << std::endl;
16+
} catch (const AppwriteException& ex) {
17+
std::cerr << "Exception: " << ex.what() << std::endl;
18+
}
19+
20+
return 0;
21+
}

examples/health/getCache.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
4+
int main() {
5+
std::string projectId = "66fbb5a100070a3a1d19";
6+
std::string apiKey = "";
7+
8+
Appwrite appwrite(projectId);
9+
Health& health = appwrite.getHealth();
10+
11+
health.setup(apiKey, projectId);
12+
13+
try {
14+
std::string response = health.getCache();
15+
std::cout << "Health Check Done! \nResponse: " << response << std::endl;
16+
} catch (const AppwriteException& ex) {
17+
std::cerr << "Exception: " << ex.what() << std::endl;
18+
}
19+
20+
return 0;
21+
}

examples/health/getDB.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
4+
int main() {
5+
std::string projectId = "66fbb5a100070a3a1d19";
6+
std::string apiKey = "";
7+
8+
Appwrite appwrite(projectId);
9+
Health& health = appwrite.getHealth();
10+
11+
health.setup(apiKey, projectId);
12+
13+
try {
14+
std::string response = health.getDB();
15+
std::cout << "Health Check Done! \nResponse: " << response << std::endl;
16+
} catch (const AppwriteException& ex) {
17+
std::cerr << "Exception: " << ex.what() << std::endl;
18+
}
19+
20+
return 0;
21+
}

examples/health/getHealth.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int main() {
1212

1313
try {
1414
std::string response = health.getHealth();
15-
std::cout << "Health fetched successfully! \nResponse: " << response << std::endl;
15+
std::cout << "Health Check Done! \nResponse: " << response << std::endl;
1616
} catch (const AppwriteException& ex) {
1717
std::cerr << "Exception: " << ex.what() << std::endl;
1818
}

examples/health/getPubSub.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
4+
int main() {
5+
std::string projectId = "66fbb5a100070a3a1d19";
6+
std::string apiKey = "";
7+
8+
Appwrite appwrite(projectId);
9+
Health& health = appwrite.getHealth();
10+
11+
health.setup(apiKey, projectId);
12+
13+
try {
14+
std::string response = health.getPubSub();
15+
std::cout << "Health Check Done! \nResponse: " << response << std::endl;
16+
} catch (const AppwriteException& ex) {
17+
std::cerr << "Exception: " << ex.what() << std::endl;
18+
}
19+
20+
return 0;
21+
}

include/classes/Health.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class Health {
1515

1616
// core
1717
std::string getHealth();
18+
std::string getAntivirus();
19+
std::string getCache();
20+
std::string getDB();
21+
std::string getPubSub();
1822

1923
private:
2024
std::string apiKey;

src/services/Health.cpp

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,77 @@ std::string Health::getHealth(){
2929
else {
3030
throw AppwriteException("Error fetching health. Status code: " + std::to_string(statusCode) + "\n\nResponse: " + response);
3131
}
32-
}
32+
}
33+
34+
std::string Health::getAntivirus(){
35+
std::string url = Config::API_BASE_URL + "/health/anti-virus";
36+
37+
std::vector<std::string> headers = Config::getHeaders(projectId);
38+
headers.push_back("X-Appwrite-Key: " + apiKey);
39+
40+
std::string response;
41+
42+
int statusCode = Utils::getRequest(url, headers, response);
43+
44+
if (statusCode == HttpStatus::OK) {
45+
return response;
46+
}
47+
else {
48+
throw AppwriteException("Error fetching anti-virus. Status code: " + std::to_string(statusCode) + "\n\nResponse: " + response);
49+
}
50+
}
51+
52+
std::string Health::getCache(){
53+
std::string url = Config::API_BASE_URL + "/health/cache";
54+
55+
std::vector<std::string> headers = Config::getHeaders(projectId);
56+
headers.push_back("X-Appwrite-Key: " + apiKey);
57+
58+
std::string response;
59+
60+
int statusCode = Utils::getRequest(url, headers, response);
61+
62+
if (statusCode == HttpStatus::OK) {
63+
return response;
64+
}
65+
else {
66+
throw AppwriteException("Error fetching cache. Status code: " + std::to_string(statusCode) + "\n\nResponse: " + response);
67+
}
68+
}
69+
70+
std::string Health::getDB(){
71+
std::string url = Config::API_BASE_URL + "/health/db";
72+
73+
std::vector<std::string> headers = Config::getHeaders(projectId);
74+
headers.push_back("X-Appwrite-Key: " + apiKey);
75+
76+
std::string response;
77+
78+
int statusCode = Utils::getRequest(url, headers, response);
79+
80+
if (statusCode == HttpStatus::OK) {
81+
return response;
82+
}
83+
else {
84+
throw AppwriteException("Error fetching DB. Status code: " + std::to_string(statusCode) + "\n\nResponse: " + response);
85+
}
86+
}
87+
88+
std::string Health::getPubSub(){
89+
std::string url = Config::API_BASE_URL + "/health/pubsub";
90+
91+
std::vector<std::string> headers = Config::getHeaders(projectId);
92+
headers.push_back("X-Appwrite-Key: " + apiKey);
93+
94+
std::string response;
95+
96+
int statusCode = Utils::getRequest(url, headers, response);
97+
98+
if (statusCode == HttpStatus::OK) {
99+
return response;
100+
}
101+
else {
102+
throw AppwriteException("Error fetching pubsub. Status code: " + std::to_string(statusCode) + "\n\nResponse: " + response);
103+
}
104+
}
105+

0 commit comments

Comments
 (0)