///|
#cfg(any(target="native", target="js"))
async test {
let (response, body) = @http.get("https://www.moonbitlang.com")
inspect(response.code, content="200")
assert_true(body.text().has_prefix("<!doctype html>"))
}///|
#cfg(any(target="native", target="js"))
async test {
let client = @http.Client("https://www.moonbitlang.com")
defer client.close()
let response = client..request(Get, "/").end_request()
inspect(response.code, content="200")
let body = client.read_all()
assert_true(body.text().has_prefix("<!doctype html>"))
}///|
#cfg(target="native")
pub async fn server(listen_addr : @socket.Addr) -> Unit {
@http.Server(listen_addr).run_forever((request, _body, conn) => {
conn..send_response(404, "NotFound").write("`\{request.path}` not found")
})
}impl Show for ProxyErrorimpl Show for URIParseErrorpub struct Client {
// private fields
}
#alias(new, deprecated="`new` is deprecated, use `Client` instead")
async fn Client::Client(uri : String, headers? : Map[String, String], proxy? : Client, verify? : Bool, trust? : TrustedRoot) -> Clientasync fn Client::request(self : Client, meth : RequestMethod, path : StringView, extra_headers? : Map[String, String]) -> Unitpub struct Cookie {
name : String
value : String
path : String?
expires_raw : String?
max_age : Int64?
domain : String?
secure : Bool
http_only : Bool
extensions : Array[String]
} derive(ToJson, Debug)
#alias(new, deprecated="`new` is deprecated, use `Cookie` instead")
fn Cookie::Cookie(name : String, value : String, path? : String, expires_raw? : String, max_age? : Int64, domain? : String, secure? : Bool, http_only? : Bool, extensions? : Array[String]) -> Cookiepub(all) struct Request {
meth : RequestMethod
path : String
headers : Map[String, String]
} derive(ToJson, Debug)async fn Server::run_forever(self : Server, f : async (Request, &Reader, ServerConnection) -> Unit, allow_failure? : Bool, max_connections? : Int) -> Unittype ServerConnectionimpl Reader for ServerConnectionasync fn _direct_read(self : ServerConnection, buf : FixedArray[Byte], offset~ : Int, max_len~ : Int) -> Intimpl Writer for ServerConnectionasync fn ServerConnection::send_response(self : ServerConnection, code : Int, reason : String, extra_headers? : Map[String, String], cookies? : Array[Cookie]) -> UnitInstall
Download zipAsynchronous programming library for MoonBit