import {
"mizchi/js_web@0.13.0",
}import {
"mizchi/js_web/http",
}///|
pub async fn get_json() -> @core.Any {
let res = @http.fetch("https://api.example.com/data", method_="GET")
res.json()
}///|
pub async fn post() -> String {
let res = @http.fetch(
"https://api.example.com/users",
method_="POST",
headers={ "content-type": "application/json" },
body=@core.identity("{\"name\":\"value\"}"),
)
res.text()
}///|
pub async fn post_request() -> String {
let init = @http.RequestInit(
http_method="POST",
body=@core.identity("{\"name\":\"value\"}"),
)
let request = @http.Request("https://api.example.com/users", init~)
(@http.fetch_request(request)).text()
}///|
pub fn respond() -> @http.Response {
@http.Response(
body="hello",
status=200,
headers=@core.from_entries([
("content-type", @core.identity("text/plain")),
]),
)
}#external
pub type FormData#external
pub type Headerspub(all) struct Request {
bodyUsed : Bool
url : String
credentials : String
}#deprecated("use `Request(url, init~)` instead")
fn Request::new_with_init(url : String, init : RequestInit) -> Requestpub struct RequestInit {
// private fields
}fn RequestInit::RequestInit(http_method? : String, headers? : Headers, body? : Any, mode? : String, credentials? : String, cache? : String, redirect? : String, referrer? : String, referrerPolicy? : String, integrity? : String, keepalive? : Bool, signal? : AbortSignal, priority? : String) -> RequestInit#deprecated("use `RequestInit(..)` instead")
fn RequestInit::new(http_method? : String, headers? : Headers, body? : Any, mode? : String, credentials? : String, cache? : String, redirect? : String, referrer? : String, referrerPolicy? : String, integrity? : String, keepalive? : Bool, signal? : AbortSignal, priority? : String) -> RequestInitpub(all) struct Response {
ok : Bool
status : Int
statusText : String
redirected : Bool
}async fn fetch(url : String, method_~ : String, headers? : Map[String, String], cache? : String, mode? : String, body? : Any, credentials? : String, integrity? : String, keepalive? : Bool, priority? : String, redirect? : String, referrer? : String, referrerPolicy? : String, signal? : AbortSignal) -> ResponseInstall
Download zipweb standard api bindings (fetch, Streams, Blob, URL, Crypto, ...)
Dependencies