Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kanarus/night_worker


https://github.com/kanarus/night_worker

Last synced: 19 days ago
JSON representation

Awesome Lists containing this project

README

        


night_worker


Ergonimic Cloudflare Workers SDK for nightly Rust


- For [fetch](https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/) use mainly
- Built upon [workers-rs](https://crates.io/crates/worker)


## Supported Bindings

- [x] KV
- [x] Service Bindings
- [x] D1 ( by `"d1"` feature )
- [x] Queues ( by `"queue"` feature )
- [ ] Durable Objects ( TODO )


## Example

*Cargo.toml*
```toml
# The same version of
# `worker` crate will be supported

[dependencies]
worker = "0.1.0"
night_worker = "0.1.0-rc"
```

*src/lib.rs*
```rust
use worker::{Request, Env, Context, Result, Response};
use night_worker::Worker;

#[worker::event(fetch)]
async fn main(
req: Request,
env: Env,
ctx: Context,
) -> Result {
let w = Worker::take_over(env, ctx);

let kv = w.KV("MY_KV")?;

kv.put("key1", "value1").await?;
kv.put("key2", "value2").expiration_ttl(1024).await?;

let value = kv.get("key1").await?;
let value = kv.get("key2").cache_ttl(1024).await?;

let all = kv.list().await?;
let all = kv.list().prefix("pref").limit(42).await?;

todo!()
}
```