#stof #http #format #data #remove #unified #sharing

stof-http

Stof is a unified data interface and interchange format for creating, sharing, and manipulating data. Stof removes the fragile and cumbersome parts of combining and using data in applications.

2 releases

new 0.1.1 Jan 13, 2025
0.1.0 Jan 5, 2025

#1876 in Network programming

Download history 150/week @ 2025-01-05 106/week @ 2025-01-12

256 downloads per month
Used in stof-cli

Apache-2.0

13KB
193 lines

Stof HTTP

Stof HTTP library. Adding this library to your Stof document allows you to make HTTP requests.

Example

Here is an example of using this library in Stof.

fn example(): str {
    let url = "https://restcountries.com/v3.1/name/germany";
                
    // Using a response object, we are telling the document to call header_import using the responses 'content-type' as a format,
    // parsing the response into this object. The object can be created like so, or be an already created obj in the document somewhere.
    let obj = new {};
    let resp = HTTP.get(url, obj);
    
    // resp is in the form (content type (str), headers (vec), body (blob))
    // return resp[2] as str; // This would convert the blob body to a string using utf-8, returning the entire response body
    
    let first = obj.field[0];
    return `${first.altSpellings[1]} has an area of ${first.area}`; // returns 'Federal Republic of Germany has an area of 357114'
}

Dependencies

~7–15MB
~189K SLoC