Crate rede_parser

Source
Expand description

Library to handle the parsing of requests in TOML format used by the crate rede.

The library offers the function rede_parser::parse_request to convert a given string into a valid rede rede_schema::Request.

§Example

Pass the correct request TOML to the parser functions to get the parsed request:


let toml = r#"
    [http]
    method = "POST"
    url = "http://localhost:8080/note"

    [headers]
    Content-Type = "application/json"

    [body]
    raw = """
    {
        "title": "Implement rede_parser" ,
        "description": "Implement it following the example
    }
    """
 "#;
 let request = rede_parser::parse_request(toml)?;
 assert_eq!(request.method, Method::POST);
 assert_eq!(request.url, "http://localhost:8080/note");
 assert_eq!(request.headers["Content-Type"], "application/json");
 if let Body::Raw { content, mime } = &request.body {
    assert_eq!(mime, &"text/plain; charset=utf-8");
    println!("{}", &request.body);
 }

Enums§

Error
Errors that can happen during the parsing

Functions§

parse_request
Attempts to parse the given string into an HTTP request.