Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/depot/connectrpc-workers
A Connect RPC adapter for Cloudflare Workers
https://github.com/depot/connectrpc-workers
cloudflare cloudflare-workers connectrpc
Last synced: 2 months ago
JSON representation
A Connect RPC adapter for Cloudflare Workers
- Host: GitHub
- URL: https://github.com/depot/connectrpc-workers
- Owner: depot
- Created: 2024-04-13T08:52:11.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-22T11:05:13.000Z (4 months ago)
- Last Synced: 2024-11-25T09:45:17.858Z (2 months ago)
- Topics: cloudflare, cloudflare-workers, connectrpc
- Language: TypeScript
- Homepage:
- Size: 99.6 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# `@depot/connectrpc-workers`
[![CI](https://github.com/depot/connectrpc-workers/actions/workflows/ci.yml/badge.svg)](https://github.com/depot/connectrpc-workers/actions/workflows/ci.yml)
[![npm](https://img.shields.io/npm/v/@depot/connectrpc-workers.svg)](https://www.npmjs.com/package/@depot/connectrpc-workers)
![Powered by TypeScript](https://img.shields.io/badge/powered%20by-typescript-blue.svg)A [Connect RPC](https://connectrpc.com/) adapter for [Cloudflare Workers](https://workers.cloudflare.com/).
## Installation
You can install the module with your favorite package manager:
```bash
pnpm add @depot/connectrpc-workers
```This package depends on the peer dependencies `@connectrpc/connect` and `@cloudflare/workers-types`.
## Usage
You can construct a function to register handlers for your Connect services, then construct a Cloudflare Workers fetch event handler from those routes:
```typescript
import type {ConnectRouter} from '@connectrpc/connect'
import {connectWorkersAdapter} from '@depot/connectrpc-workers'function routes(router: ConnectRouter) {
// implement rpc Say(SayRequest) returns (SayResponse)
router.rpc(ElizaService, ElizaService.methods.say, async (req) => ({
sentence: `you said: ${req.sentence}`,
}))
}const handler = connectWorkersAdapter({routes})
export default {
fetch(request, env, context) {
return handler(request, env, context)
},
} satisfies ExportedHandler
```## License
MIT License, see `LICENSE`.