Skip to content
Simple, lightweight and straight-forward way of doing HTTP(S) requests with the help of ARM's open-source MbedTLS library.
C Shell HTML Python CMake C++ Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
docs
examples
include
lib
src
.clang-format
.gitattributes
.gitignore
CMakeLists.txt
LICENSE
README.md
doxyfile

README.md

API Docs License Shield

Glitched HTTPS

Simple, lightweight and straight-forward way of doing HTTP(S) requests in C with the help of ARM's open-source MbedTLS library.

ᐳᐳ Check out the API docs here on github.io

How to clone

git clone https://github.com/GlitchedPolygons/glitchedhttps.git

How to use

Just add glitchedhttps as a git submodule to your project (e.g. into some lib/ or deps/ folder inside your project's repo; {repo_root}/lib/ is used here in the following example).

git submodule add https://github.com/GlitchedPolygons/glitchedhttps.git lib/ git submodule update --init --recursive

If you use CMake you can just add_subdirectory(path_to_submodule) and then target_link_libraries(your_project PRIVATE glitchedhttps) inside your CMakeLists.txt file.

Simple GET Request

Here's how you can get started. Quick and easy setup:

#include <glitchedhttps.h>

int main() 
{
    /* 
     * Please note that you MUST include the scheme, 
     * ergo the URL must start with `http://` or `https://` 
     * (it won't default to one of the two!). 
     */

    glitchedhttps_request request = 
    {
        .url = "https://example.com/",
        .method = GLITCHEDHTTPS_GET,
        .ssl_verification_optional = false,
    };

    glitchedhttps_response* response = NULL;

    int result = glitchedhttps_submit(&request, &response);

    if (result == GLITCHEDHTTPS_SUCCESS)
    {
        printf("\n SUCCESS! \n");
    }

    printf("\n Response from %s: \n\n %s \n", request.url, response != NULL ? response->content : "(NULL)");
    
    glitchedhttps_response_free(response);
}

POST Request example

Sending POST requests with parameters, request body, custom HTTP headers and everything is possible!

Also: NEVER forget to glitchedhttps_response_free(response); to prevent memory leaks!

Check out the other examples inside the examples/ folder too!

#include <glitchedhttps.h>

int main()
{
    char* url = "https://postman-echo.com/post";
    char* body = "{ \"foo\" : \"bar\", \"test\" : \"value\" }";
    
    glitchedhttps_header additional_headers[] = 
    {
        { "Another-Foo", "anotherBar" },
        { "Additional-Headers-Are-Cool", "SGVsbG8gV29ybGQh" },
        { "Yet-Another-Header", "You can add as many of these as you want" }
    };
    
    glitchedhttps_request request = 
    {
        .url = url,
        .method = GLITCHEDHTTPS_POST,
        .ssl_verification_optional = false,
        .content_type = "application/json",
        .content_length = strlen(body),
        .content = body,
        .additional_headers = additional_headers,
        .additional_headers_count = sizeof(additional_headers) / sizeof(glitchedhttps_header)
    };

    glitchedhttps_response* response = NULL;

    int result = glitchedhttps_submit(&request, &response);

    const bool success =
        result == GLITCHEDHTTPS_SUCCESS
        && response != NULL
        && response->status_code >= 200
        && response->status_code < 300;

    if (success)
    {
        printf("\n Connection test SUCCESSFUL! Status Code: %d \n", response->status_code);
    }

    printf("\n Response from %s: \n\n %s \n", request.url, response != NULL ? response->content : "(NULL)");

    glitchedhttps_response_free(response);

    return 0;
}
You can’t perform that action at this time.