Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ Hello, your_name!

- [worker](https://github.com/cloudflare/workers-rs) _v0.6.\*_

Ohkami has first-class support for Cloudflare Workers. For example,
Ohkami has first-class support for Cloudflare Workers:

- provides `#[bindings]`, `ws::SessionMap` helper
- provides better `DurableObject`
- `#[worker]` macro to define a Worker
- `#[bindings]`, `ws::SessionMap` helper
- better `DurableObject`
- not require `Send` `Sync` bound for handlers or fangs
- [worker_openapi.js](https://github.com/ohkami-rs/ohkami/tree/main/scripts/worker_openapi.js) script to generate OpenAPI document from `#[worker]` fn

And also maintains useful project template. Run :

Expand All @@ -92,17 +94,21 @@ npm create cloudflare <project dir> -- --template https://github.com/ohkami-

then `<project dir>` will have `wrangler.jsonc`, `package.json` and a Rust library crate.

A `#[ohkami::worker]` (async/sync) fn returning `Ohkami` is the Worker definition.
`#[ohkami::worker] async? fn({bindings}?) -> Ohkami` is the Worker definition.

Local dev by `npm run dev` and deploy by `npm run deploy` !

See README of [template](https://github.com/ohkami-rs/ohkami-templates/tree/main/worker) for details.
See

- `worker.*` temaplates in [template repository](https://github.com/ohkami-rs/ohkami-templates)
- `worker.*` samples in [samples directory](https://github.com/ohkami-rs/ohkami/tree/main/samples)
- `#[worker]`'s documentation comment in [macro definitions](https://github.com/ohkami-rs/ohkami/tree/main/ohkami_macros/src/lib.rs)

Or, here are [Workers + OpenAPI template](https://github.com/ohkami-rs/ohkami-templates/tree/main/worker-openapi) and [Workers + SPA with Yew template](https://github.com/ohkami-rs/ohkami-templates/tree/main/worker_yew_spa).
for wokring examples and detailed usage of `#[worker]` (and/or `openapi`).

### `"rt_lambda"` : AWS Lambda

- [lambda_runtime](https://github.com/awslabs/aws-lambda-rust-runtime) _v0.14.\*_ (with `tokio`)
- [lambda_runtime](https://github.com/awslabs/aws-lambda-rust-runtime) _v0.14.\*_ with `tokio`

Both `Function URLs` and `API Gateway` are supported, and WebSocket is not supported.

Expand Down
33 changes: 31 additions & 2 deletions ohkami_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ pub fn operation(args: proc_macro::TokenStream, handler: proc_macro::TokenStream
/// Create an worker Ohkami, running on Cloudflare Workers !
///
/// - This only handle `fetch` event.
/// - Expected signature: `() -> Ohkami` ( both sync/async are available )
/// - Expected signature: `() -> Ohkami` or `(bindings) -> Ohkami` ( both sync/async are available )
///
/// `(bindings) -> Ohkami` pattern is called **global bindings**.
///
/// ---
/// *lib.rs*
/// ```ignore
/// use ohkami::prelude::*;
///
Expand All @@ -136,6 +137,34 @@ pub fn operation(args: proc_macro::TokenStream, handler: proc_macro::TokenStream
/// }
/// ```
/// ---
/// ```ignore
/// use ohkami::{prelude::*, worker, bindings};
///
/// #[bindings]
/// struct Bindings {
/// MY_KV: bindings::KV,
/// }
///
/// async fn get_from_kv(
/// Path(key): Path<String>,
/// Context(kv): Context<'_, bindings::KV>,
/// ) -> Result<String, worker::Error> {
/// kv.get(&key).text().await?.ok_or_else(|| worker::Error::RustError(
/// format!("Key '{}' not found in KV", key)
/// ))
/// }
///
/// #[worker]
/// // global bindings
/// fn my_ohkami(b: Bindings) -> Ohkami {
/// Ohkami::new((
/// Context::new(b.MY_KV),
/// "/".GET(|| async {"Hello, world!"}),
/// "/kv/:key".GET(get_from_kv),
/// ))
/// }
/// ```
/// ---
///
/// `#[worker]` accepts an argument in following format for *document purpose*:
///
Expand Down