Struct worker::RouteContext
source · pub struct RouteContext<D> {
pub data: D,
pub env: Env,
/* private fields */
}
Expand description
Container for a route’s parsed parameters, data, and environment bindings from the Runtime (such as KV Stores, Durable Objects, Variables, and Secrets).
Fields§
§data: D
§env: Env
Implementations§
source§impl<D> RouteContext<D>
impl<D> RouteContext<D>
sourcepub fn data(&self) -> &D
👎Deprecated since 0.0.8: please use the data
field directly
pub fn data(&self) -> &D
data
field directlyGet a reference to the generic associated data provided to the Router
.
sourcepub fn get_env(self) -> Env
👎Deprecated since 0.0.8: please use the env
field directly
pub fn get_env(self) -> Env
env
field directlyGet the Env
for this Worker. Typically users should opt for the secret
, var
, kv
and
durable_object
methods on the RouteContext
instead.
sourcepub fn secret(&self, binding: &str) -> Result<Secret>
pub fn secret(&self, binding: &str) -> Result<Secret>
Get a Secret value associated with this Worker, should one exist.
sourcepub fn var(&self, binding: &str) -> Result<Var>
pub fn var(&self, binding: &str) -> Result<Var>
Get an Environment Variable value associated with this Worker, should one exist.
sourcepub fn kv(&self, binding: &str) -> Result<KvStore>
pub fn kv(&self, binding: &str) -> Result<KvStore>
Get a KV Namespace associated with this Worker, should one exist.
sourcepub fn durable_object(&self, binding: &str) -> Result<ObjectNamespace>
pub fn durable_object(&self, binding: &str) -> Result<ObjectNamespace>
Get a Durable Object Namespace associated with this Worker, should one exist.
sourcepub fn param(&self, key: &str) -> Option<&String>
pub fn param(&self, key: &str) -> Option<&String>
Get a URL parameter parsed by the router, by the name of its match or wildcard placeholder.
sourcepub fn service(&self, binding: &str) -> Result<Fetcher>
pub fn service(&self, binding: &str) -> Result<Fetcher>
Get a Service Binding for Worker-to-Worker communication.
sourcepub fn bucket(&self, binding: &str) -> Result<Bucket>
pub fn bucket(&self, binding: &str) -> Result<Bucket>
Get a R2 Bucket associated with this Worker, should one exist.
sourcepub fn d1(&self, binding: &str) -> Result<D1Database>
pub fn d1(&self, binding: &str) -> Result<D1Database>
Access a D1 Database by the binding name configured in your wrangler.toml file.