@@ -121,10 +121,11 @@ pub fn operation(args: proc_macro::TokenStream, handler: proc_macro::TokenStream
121121/// Create an worker Ohkami, running on Cloudflare Workers !
122122///
123123/// - This only handle `fetch` event.
124- /// - Expected signature: `() -> Ohkami` ( both sync/async are available )
124+ /// - Expected signature: `() -> Ohkami` or `(bindings) -> Ohkami` ( both sync/async are available )
125+ ///
126+ /// `(bindings) -> Ohkami` pattern is called **global bindings**.
125127///
126128/// ---
127- /// *lib.rs*
128129/// ```ignore
129130/// use ohkami::prelude::*;
130131///
@@ -136,6 +137,34 @@ pub fn operation(args: proc_macro::TokenStream, handler: proc_macro::TokenStream
136137/// }
137138/// ```
138139/// ---
140+ /// ```ignore
141+ /// use ohkami::{prelude::*, worker, bindings};
142+ ///
143+ /// #[bindings]
144+ /// struct Bindings {
145+ /// MY_KV: bindings::KV,
146+ /// }
147+ ///
148+ /// async fn get_from_kv(
149+ /// Path(key): Path<String>,
150+ /// Context(kv): Context<'_, bindings::KV>,
151+ /// ) -> Result<String, worker::Error> {
152+ /// kv.get(&key).text().await?.ok_or_else(|| worker::Error::RustError(
153+ /// format!("Key '{}' not found in KV", key)
154+ /// ))
155+ /// }
156+ ///
157+ /// #[worker]
158+ /// // global bindings
159+ /// fn my_ohkami(b: Bindings) -> Ohkami {
160+ /// Ohkami::new((
161+ /// Context::new(b.MY_KV),
162+ /// "/".GET(|| async {"Hello, world!"}),
163+ /// "/kv/:key".GET(get_from_kv),
164+ /// ))
165+ /// }
166+ /// ```
167+ /// ---
139168///
140169/// `#[worker]` accepts an argument in following format for *document purpose*:
141170///
0 commit comments