An Arduino library for building HTTP requests.
#include <RequestBuilder.h>
WiFiClient client;
void postRequest(){
RequestBuilder *request = new RequestBuilder(
"POST",
"example.com",
"/path/to/resource"
);
// Add query parameters
request->query.add("key", "value");
// Add request body form data
request->body.add("data", "value");
// Establish connection
client.connect(request->host.c_str(), 80);
// Send request
client.print(request->getRequest());
delete request;
// Read response and print to serial
while (client.connected()) {
String line = client.readStringUntil('\r');
Serial.println(line);
}
}
For more examples, see the examples directory.
A class for storing key-value pairs. Used for storing query parameters and request body form data.
Add a key-value pair to the parameter.
Remove a key-value pair with specified key from the parameter.
Get all url-encoded key-value pairs containing with given grue string in key
value_grue
value
key_grue
key
... format.
A short-hand of get("&", "=")
. Get all key-value pairs in key=value&key=value
format.
Similar to get(key_grue, value_grue)
, but does not encode the key-value pairs.
Get the number of key-value pairs in the parameter.
Concatenate two parameters, overwriting the original parameter.
Sort the parameter by key alphabetically.
A class for building HTTP requests.
Create a new request with specified method, host and path. All parameters can be omitted.
The host of the request.
The path of the request.
The method of the request.
The query parameters of the request.
The request body form data of the request.
The authentication parameters of the request. Used for making OAuth 1.0 requests.
Get the request line of the request.
ex: GET /path/to/resource?key=value&key2=value2 HTTP/1.1
Get all request headers of the request.
The Host
header is automatically set with the host set at initialization.
When the request has a body, the Content-Type
header is set to application/x-www-form-urlencoded
and Content-Length
header is set to the length of the body.
Get the full request content.
This concatenates all the auth, query, body parameters and returns a string in key=value&key=value
format, sorted by key alphabetically. This is used for generating the signature base string for OAuth 1.0 requests.
Get the URL of the request without query string.
ex: getUrl("http") ==> http://example.com/path/to/resource