/// This is currently unstable and may stop working on the IC with little or no
/// warning
///
/// This allows you to use a canister as an HTTP server
///
/// # Example
///
/// ```no_run
/// # use dfn_http::*;
/// #[export_name = "canister_query http_query"]
/// pub fn main() {
///     http(handler)
/// }
///
/// fn handler(http: RequestWrapper) -> Response {
/// // Take the request and return a response
/// # Response::from_status_code(404)
/// }
/// ```
/// Requests send to query.<canister_id>.<ic_domain> will reach the handler
This is currently unstable and may stop working on the IC with little or no
warning

This allows you to use a canister as an HTTP server
This is currently unstable and may stop working on the IC with little or no warning This allows you to use a canister as an HTTP server
pub fn http<F>(handler: F)
where
    F: FnOnce(RequestWrapper) -> Response,
{
    let caller = dfn_core::api::caller().into_vec();
    // Generate CanisterHttp id which is a bunch of 0s then a 5
    let mut http_caller: Vec<u8> = vec![0; caller.len()];
    let end = http_caller
        .last_mut()
        .expect("The caller id had a length of zero");
    *end = HTTP_CANISTER_ID;
    if http_caller == caller {
        http_unchecked(handler)
    } else {
        panic!(
            "Expected caller {:?} but found caller {:?}",
            http_caller, caller
        )
    }
}
pub fn http < F > ( handler : F ) where F : FnOnce ( RequestWrapper ) -> Response , { let caller = dfn_core :: api :: caller ( ) . into_vec ( ) ; // Generate CanisterHttp id which is a bunch of 0s then a 5 let mut http_caller : Vec < u8 > = vec ! [ 0 caller len ( ) ] ; let end = http_caller . last_mut ( ) . expect ( " " ) ; * end = HTTP_CANISTER_ID ; if http_caller == caller { http_unchecked ( handler ) } else { panic ! ( " " http_caller caller ) } }
This is currently unstable and may stop working on the IC with little or no
warning
This is currently unstable and may stop working on the IC with little or no warning
handler
F
example
None
use dfn_http::*;
None
[export_name = "canister_query http_query"]
pub fn main() {
http(handler)
}

fn handler -> Response {
Take the request and return a response
pub fn main () { http ( handler ) } fn handler - > Response { Take the request and return a response
response::from_status_code(404)
}
```
Requests send to query.. will reach the handler
} ` ` ` Requests send to query .. will reach the handler