pub struct EggfetchClient { /* private fields */ }Expand description
HTTP client wrapping eggfetch-ffi.
The client pointer is stored as a [SendClientPtr] raw-pointer wrapper
to satisfy napi’s Send requirement for async futures while preserving
pointer provenance (no usize ↔ *mut round-trip). The underlying
ClientHandle is Send + Sync per eggfetch-ffi documentation.
§Lifetime safety for in-flight requests
Copying the raw pointer into a 'static future is safe here because of
how napi-rs (2.x) generates async class methods: before launching the
future it creates a strong napi_ref (refcount 1) on this
(napi_create_reference) and releases it only when the future resolves
(see napi-derive-backend codegen, NapiRefContainer). A strong
reference prevents garbage collection and finalization of the JS object,
so Drop for EggfetchClient cannot free the FFI handle while any
request future is outstanding. Do not replace this with a pattern that
frees the handle independently of napi’s reference tracking without
adding an equivalent guard.
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.