Code Monkey home page Code Monkey logo

request-builder's Introduction

Request Builder

An Arduino library for building HTTP requests.

Usage for POST request

#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.

Documentation

Parameter

A class for storing key-value pairs. Used for storing query parameters and request body form data.

add(key, value)

Add a key-value pair to the parameter.

remove(key)

Remove a key-value pair with specified key from the parameter.

get(key_grue, value_grue)

Get all url-encoded key-value pairs containing with given grue string in key value_grue value key_grue key ... format.

get()

A short-hand of get("&", "="). Get all key-value pairs in key=value&key=value format.

getRaw(key_grue, value_grue)

Similar to get(key_grue, value_grue), but does not encode the key-value pairs.

size()

Get the number of key-value pairs in the parameter.

concat(parameter)

Concatenate two parameters, overwriting the original parameter.

sort()

Sort the parameter by key alphabetically.

RequestBuilder

A class for building HTTP requests.

new Request(method, host, path)

Create a new request with specified method, host and path. All parameters can be omitted.

host

The host of the request.

path

The path of the request.

method

The method of the request.

query : Parameter

The query parameters of the request.

body : Parameter

The request body form data of the request.

auth : Parameter

The authentication parameters of the request. Used for making OAuth 1.0 requests.

getRequestLine()

Get the request line of the request. ex: GET /path/to/resource?key=value&key2=value2 HTTP/1.1

getRequestHeader();

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.

getRequest()

Get the full request content.

getParameterString()

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.

getUrl(protocol)

Get the URL of the request without query string. ex: getUrl("http") ==> http://example.com/path/to/resource

request-builder's People

Contributors

plageoj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.