Http class can be used to make http calls over the connected Wi-Fi network.
It operates in completely asynchronous fashion to prevent lock ups and is designed with ease of use in mind.
To make an http call, create an instance of
Http class as follows:
Http request = Http("example.com");
The prototype of the
Http class constructor is as follows:
Http(const char* host, int port = 80);
Http class object is instantiated, we can make
DELETE requests with the following function respectively:
void get(const char* path);
void post(const char* path, const char* body = NULL);
void put(const char* path, const char* body = NULL);
void del(const char* path, const char* body = NULL);
In these the
path is the path of the endpoint relative to host (for example,
body takes a const char string for the request body.
To add any header to the request, use:
void addHeader(const char* header);
To set the
Content-Type for the request, use:
void setContentType(const char* content_type);
To get the data that is returned from the response, you can use:
void writeResponseTo(char* response);
This takes as parameter the pointer to a char array where the response is written once returned from the network request.
Once the request is made by calling one of the
del methods, the status of the request can be checked asynchronously using:
Which returns a bool indicating whether the request is complete or not, successfully or otherwise.
This returns the status code of the reponse returned.
If the request is not complete yet or fails, then one of the below constants may also be returned: