This repository was archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRestClient.h
More file actions
107 lines (84 loc) · 2.26 KB
/
RestClient.h
File metadata and controls
107 lines (84 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef RestClient_h
#define RestClient_h
#include <Arduino.h>
#include <WiFiClientSecure.h>
class RestClient
{
public:
RestClient(String host)
{
RestClient(host, 80);
}
RestClient(String host, int port)
{
RestClient(host, port, "http");
}
RestClient(String host, int port, String protocol)
{
RestClient(host, port, protocol, "");
}
RestClient(String host, int port, String protocol, String basePath);
int request(String method, String path, const char *body, String *response);
void setHeader(String header);
void setContentType(String contentType);
void setProtocol(String protocol);
int get(String path)
{
return request("GET", path, NULL, NULL);
}
int get(String path, String *response)
{
return request("GET", path, NULL, response);
}
int post(String path, String body)
{
return request("POST", path, body.c_str(), NULL);
}
int post(String path, String body, String *response)
{
return request("POST", path, body.c_str(), response);
}
int patch(String path, String body)
{
return request("PATCH", path, body.c_str(), NULL);
}
int patch(String path, String body, String *response)
{
return request("PATCH", path, body.c_str(), response);
}
int put(String path, String body)
{
return request("PUT", path, body.c_str(), NULL);
}
int put(String path, String body, String *response)
{
return request("PUT", path, body.c_str(), response);
}
int del(String path)
{
return request("DELETE", path, NULL, NULL);
}
int del(String path, String *response)
{
return request("DELETE", path, NULL, response);
}
int del(String path, String body)
{
return request("DELETE", path, body.c_str(), NULL);
}
int del(String path, String body, String *response)
{
return request("DELETE", path, body.c_str(), response);
}
private:
WiFiClient *client;
int _readResponse(String *response);
String host;
int port;
int num_headers;
String headers[10];
String contentType;
int ssl;
String basePath;
};
#endif