pub struct EggfetchClient { /* private fields */ }Expand description
HTTP client wrapping eggfetch-ffi.
The underlying ClientHandle is shared via Arc<ClientHandleInner> so
in-flight spawn_blocking requests extend its lifetime independently of
napi-rs finalization order. The raw pointer preserves provenance (no
usize ↔ *mut round-trip); the underlying ClientHandle is Send + Sync
per eggfetch-ffi documentation.
§Lifetime safety for in-flight requests
Each request clones the Arc into its 'static future before entering
spawn_blocking. Drop for ClientHandleInner frees the FFI handle only
when the last clone (client plus all in-flight requests) is dropped, so
a JS garbage-collection of the client object cannot free the handle
underneath a running request. Do not replace this with a pattern that
frees the handle from Drop for EggfetchClient directly without holding
the shared Arc alive in the future.
This remains an experimental prototype (see lib.rs): requests execute
through the synchronous C ABI inside spawn_blocking.
Implementations§
Source§impl EggfetchClient
impl EggfetchClient
pub fn into_reference( val: EggfetchClient, env: Env, ) -> Result<Reference<EggfetchClient>>
pub fn into_instance(self, env: Env) -> Result<ClassInstance<EggfetchClient>>
Source§impl EggfetchClient
impl EggfetchClient
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new client with default settings.
§Errors
Returns an error if the underlying FFI client allocation fails.
Sourcepub async fn get(&self, url: String) -> Result<EggfetchResponse>
pub async fn get(&self, url: String) -> Result<EggfetchResponse>
Send a GET request and return the response.
§Errors
Returns an error if the request fails or the URL is invalid.
Sourcepub async fn post(
&self,
url: String,
body: Option<String>,
) -> Result<EggfetchResponse>
pub async fn post( &self, url: String, body: Option<String>, ) -> Result<EggfetchResponse>
Send a POST request with optional body.
§Errors
Returns an error if the request fails or the URL/body is invalid.
Sourcepub async fn put(
&self,
url: String,
body: Option<String>,
) -> Result<EggfetchResponse>
pub async fn put( &self, url: String, body: Option<String>, ) -> Result<EggfetchResponse>
Send a PUT request with optional body.
§Errors
Returns an error if the request fails or the URL/body is invalid.
Sourcepub async fn patch(
&self,
url: String,
body: Option<String>,
) -> Result<EggfetchResponse>
pub async fn patch( &self, url: String, body: Option<String>, ) -> Result<EggfetchResponse>
Send a PATCH request with optional body.
§Errors
Returns an error if the request fails or the URL/body is invalid.
Sourcepub async fn delete(&self, url: String) -> Result<EggfetchResponse>
pub async fn delete(&self, url: String) -> Result<EggfetchResponse>
Sourcepub async fn head(&self, url: String) -> Result<EggfetchResponse>
pub async fn head(&self, url: String) -> Result<EggfetchResponse>
Sourcepub async fn options(&self, url: String) -> Result<EggfetchResponse>
pub async fn options(&self, url: String) -> Result<EggfetchResponse>
Sourcepub async fn request(
&self,
method: String,
url: String,
body: Option<String>,
) -> Result<EggfetchResponse>
pub async fn request( &self, method: String, url: String, body: Option<String>, ) -> Result<EggfetchResponse>
Send a request with a custom method.
The optional body is UTF-8 text only; arbitrary binary payloads (interior NUL) are rejected with an error. Use a byte-oriented API for binary uploads.
§Errors
Returns an error if the request fails or the method/URL is invalid.