///|
#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 URIParseErrorimpl Compare for CaseInsensitiveStringimpl Eq for CaseInsensitiveStringimpl Hash for CaseInsensitiveStringimpl Show for CaseInsensitiveStringimpl Debug for CaseInsensitiveStringtype Client#alias(new, deprecated="`new` is deprecated, use `Client` instead")
async fn Client::Client(uri : String, headers? : Map[CaseInsensitiveString, String], proxy? : Client, verify? : Bool, trust? : TrustedRoot) -> Clientasync fn Client::request(self : Client, meth : RequestMethod, path : StringView, extra_headers? : Map[CaseInsensitiveString, String]) -> Unitpub(all) struct Request {
meth : RequestMethod
path : String
headers : Map[CaseInsensitiveString, String]
} derive(ToJson, Debug)#alias(new, deprecated="`new` is deprecated, use `Server` instead")
async fn Server::Server(addr : Addr, dual_stack? : Bool, reuse_addr? : Bool, headers? : Map[CaseInsensitiveString, String]) -> Serverasync 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 ServerConnectionfn ServerConnection::new(conn : Tcp, headers? : Map[CaseInsensitiveString, String]) -> ServerConnectionasync fn ServerConnection::read(self : ServerConnection, dst : FixedArray[Byte], offset? : Int, max_len? : Int) -> Intasync fn ServerConnection::send_response(self : ServerConnection, code : Int, reason : String, extra_headers? : Map[CaseInsensitiveString, String], cookies? : Array[Cookie]) -> Unitasync fn ServerConnection::write_once(self : ServerConnection, buf : Bytes, offset~ : Int, len~ : Int) -> Intasync fn ServerConnection::write_string_interpolation(self : ServerConnection, data : &Data) -> Unitasync fn post_stream(uri : String, headers? : Map[CaseInsensitiveString, String], proxy? : Client) -> Clientasync fn put_stream(uri : String, headers? : Map[CaseInsensitiveString, String], proxy? : Client) -> Clientasync fn request(uri : String, meth : RequestMethod, headers : Map[CaseInsensitiveString, String], body : &Data, proxy? : Client) -> (Response, &Data)Install
Download zipAsynchronous programming library for MoonBit