///|
#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 URIParseErrortype Client#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(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]) -> Unitasync fn ServerConnection::write_string_interpolation(self : ServerConnection, data : &Data) -> UnitAsynchronous programming library for MoonBit