I’m trying to implement simple http functionality, using the http_request method, in rust.
It works great for query calls, but eventually I’ll need to support mutable requests, and / or I’ll need to log the calls. I can’t seem to find anything that works.
I’ve tried calling an update function from the query, like so:
async fn testz() {
ic_cdk::println!("IN");
let call_result: Result<(String,), _> = ic_cdk::api::call::call(
ic_cdk::export::Principal::from_text("rrkah-fqaaa-aaaaa-aaaaq-cai").unwrap(),
"greetUpdate",
("TEST",),
)
.await;
let v = match call_result {
Ok(it) => it.0,
Err(e) => e.1,
};
ic_cdk::println!("OUT {}", v);
}
… and call it like so:
ic_cdk::block_on(testz());
If i call this function from an update call, it works. If I call it from a query function, it doesn’t work. Am I doing something wrong, or is it just not something that’s supported right now? Are there any plans of supporting a case like this?
I also tried annotating the http_request function as an update function:
#[update(name = "http_request")]
fn http_request(request: HttpRequest) -> HttpResponse {
ic_cdk::println!("{:?}", request);
… but then I get the following error when calling the endpoint:
Details: ReplicaError { reject_code: 3, reject_message: IC0302: Canister rrkah-fqaaa-aaaaa-aaaaq-cai has no query method \'http_request\' }
Any ideas?