Skip to main content

rl_lang/interpreter/stdlib/http/
mod.rs

1//! `std::http` - a minimal HTTP server (`tiny_http`) and client (`ureq`).
2
3use crate::interpreter::native::Module;
4
5mod common;
6mod http_get;
7mod http_post;
8mod http_request;
9mod http_request_body;
10mod http_request_header;
11mod http_request_method;
12mod http_request_url;
13mod http_respond;
14mod http_server_recv;
15mod http_server_start;
16mod http_server_stop;
17mod http_server_try_recv;
18
19pub const KEYWORDS: &[&str] = &[
20    "http_server_start",
21    "http_server_recv",
22    "http_server_try_recv",
23    "http_request_method",
24    "http_request_url",
25    "http_request_header",
26    "http_request_body",
27    "http_respond",
28    "http_server_stop",
29    "http_get",
30    "http_post",
31    "http_request",
32];
33
34/// A single native HTTP resource, stored behind an `int` handle.
35pub enum HttpHandle {
36    Server(tiny_http::Server),
37    Request(tiny_http::Request),
38}
39
40pub fn module() -> Module {
41    Module::new("http")
42        .with_function("http_server_start", http_server_start::func)
43        .with_function("http_server_recv", http_server_recv::func)
44        .with_function("http_server_try_recv", http_server_try_recv::func)
45        .with_function("http_request_method", http_request_method::func)
46        .with_function("http_request_url", http_request_url::func)
47        .with_function("http_request_header", http_request_header::func)
48        .with_function("http_request_body", http_request_body::func)
49        .with_raw_function("http_respond", http_respond::func)
50        .with_function("http_server_stop", http_server_stop::func)
51        .with_function("http_get", http_get::func)
52        .with_raw_function("http_post", http_post::func)
53        .with_raw_function("http_request", http_request::func)
54}