ark_api_ffi/ffi/
http_request_v1.rs

1define_api_id!(0xa611_870d_dd2d_94d1, "http-request-v1");
2
3use crate::FFIResult;
4
5pub type RequestHandle = u32;
6
7#[ark_api_macros::ark_bindgen(imports = "ark-http-request-v1")]
8mod http_request {
9    use super::*;
10
11    /// Magic status value indicating that the request is still pending.
12    pub const STATUS_PENDING: u32 = u32::max_value();
13
14    /// HTTP request method
15    #[repr(u32)]
16    #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
17    pub enum Method {
18        /// GET method
19        Get = 1,
20
21        /// POST method
22        Post = 2,
23
24        /// PUT method
25        Put = 3,
26
27        /// DELETE method
28        Delete = 4,
29
30        /// PATCH method
31        Patch = 5,
32
33        /// HEAD method
34        Head = 6,
35
36        /// OPTIONS method
37        Options = 7,
38
39        /// TRACE method
40        Trace = 8,
41
42        /// CONNECT method
43        Connect = 9,
44    }
45
46    extern "C" {
47        /// Issue HTTP async request and returns handle.
48        pub fn request(method: Method, url: &str, body: &[u8]) -> FFIResult<RequestHandle>;
49
50        /// Check if the request is done and returns the status code of the response when it is
51        /// ready. A status code of 0 indicates that the request isn't done yet.
52        pub fn is_ready(handle: RequestHandle, out_status: &mut u32) -> FFIResult<()>;
53
54        /// Retrieve response data.
55        pub fn retrieve(handle: RequestHandle) -> FFIResult<Vec<u8>>;
56    }
57}
58
59pub use http_request::*;