feat: add HTTP client support

Add Http effect for making HTTP requests:
- Http.get(url) - GET request
- Http.post(url, body) - POST with string body
- Http.postJson(url, json) - POST with JSON body
- Http.put(url, body) - PUT request
- Http.delete(url) - DELETE request

Returns Result<HttpResponse, String> where HttpResponse contains
status code, body, and headers.

Includes reqwest dependency with blocking client, OpenSSL support
in flake.nix, and example at examples/http.lux demonstrating
API requests with JSON parsing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 16:30:48 -05:00
parent ef9746c2fe
commit 296686de17
7 changed files with 1168 additions and 14 deletions

View File

@@ -986,6 +986,84 @@ impl TypeEnv {
},
);
// Add Http effect
let http_response_type = Type::Record(vec![
("status".to_string(), Type::Int),
("body".to_string(), Type::String),
("headers".to_string(), Type::List(Box::new(Type::Tuple(vec![Type::String, Type::String])))),
]);
env.effects.insert(
"Http".to_string(),
EffectDef {
name: "Http".to_string(),
type_params: Vec::new(),
operations: vec![
EffectOpDef {
name: "get".to_string(),
params: vec![("url".to_string(), Type::String)],
return_type: Type::App {
constructor: Box::new(Type::Named("Result".to_string())),
args: vec![http_response_type.clone(), Type::String],
},
},
EffectOpDef {
name: "post".to_string(),
params: vec![
("url".to_string(), Type::String),
("body".to_string(), Type::String),
],
return_type: Type::App {
constructor: Box::new(Type::Named("Result".to_string())),
args: vec![http_response_type.clone(), Type::String],
},
},
EffectOpDef {
name: "postJson".to_string(),
params: vec![
("url".to_string(), Type::String),
("json".to_string(), Type::Named("Json".to_string())),
],
return_type: Type::App {
constructor: Box::new(Type::Named("Result".to_string())),
args: vec![http_response_type.clone(), Type::String],
},
},
EffectOpDef {
name: "put".to_string(),
params: vec![
("url".to_string(), Type::String),
("body".to_string(), Type::String),
],
return_type: Type::App {
constructor: Box::new(Type::Named("Result".to_string())),
args: vec![http_response_type.clone(), Type::String],
},
},
EffectOpDef {
name: "delete".to_string(),
params: vec![("url".to_string(), Type::String)],
return_type: Type::App {
constructor: Box::new(Type::Named("Result".to_string())),
args: vec![http_response_type.clone(), Type::String],
},
},
EffectOpDef {
name: "setHeader".to_string(),
params: vec![
("name".to_string(), Type::String),
("value".to_string(), Type::String),
],
return_type: Type::Unit,
},
EffectOpDef {
name: "setTimeout".to_string(),
params: vec![("seconds".to_string(), Type::Int)],
return_type: Type::Unit,
},
],
},
);
// Add Some and Ok, Err constructors
// Some : fn(a) -> Option<a>
let a = Type::var();