define_api_id!(0xa611_870d_dd2d_94d1, "http-request-v1");
use crate::FFIResult;
pub type RequestHandle = u32;
#[ark_api_macros::ark_bindgen(imports = "ark-http-request-v1")]
mod http_request {
use super::*;
/// Magic status value indicating that the request is still pending.
pub const STATUS_PENDING: u32 = u32::max_value();
/// HTTP request method
#[repr(u32)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum Method {
/// GET method
Get = 1,
/// POST method
Post = 2,
/// PUT method
Put = 3,
/// DELETE method
Delete = 4,
/// PATCH method
Patch = 5,
/// HEAD method
Head = 6,
/// OPTIONS method
Options = 7,
/// TRACE method
Trace = 8,
/// CONNECT method
Connect = 9,
}
extern "C" {
/// Issue HTTP async request and returns handle.
pub fn request(method: Method, url: &str, body: &[u8]) -> FFIResult<RequestHandle>;
/// Check if the request is done and returns the status code of the response when it is
/// ready. A status code of 0 indicates that the request isn't done yet.
pub fn is_ready(handle: RequestHandle, out_status: &mut u32) -> FFIResult<()>;
/// Retrieve response data.
pub fn retrieve(handle: RequestHandle) -> FFIResult<Vec<u8>>;
}
}
pub use http_request::*;