https://github.com/evex-dev/xrpc-hono
https://github.com/evex-dev/xrpc-hono
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/evex-dev/xrpc-hono
- Owner: evex-dev
- License: mit
- Created: 2024-12-31T09:52:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-24T20:28:40.000Z (9 months ago)
- Last Synced: 2025-09-25T18:28:33.904Z (9 months ago)
- Language: TypeScript
- Homepage: https://jsr.io/@evex/xrpc-hono
- Size: 127 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xrpc-hono
TypeScript library for implementing atproto HTTP API services with Hono and Lexicon schema validation.
[](https://www.npmjs.com/package/@evex-dev/xrpc-hono)
## Installation
Install from npm:
```sh
npm install @evex-dev/xrpc-hono
# or
pnpm add @evex-dev/xrpc-hono
```
## CLI
A small CLI is included for generating server bindings from Lexicon files.
```sh
# generate server files from lexicon JSON
gen-xrpc-hono ./src/lexicons/ ./lexicons/io/example/*.json
```
## Usage
### With generated server bindings
```ts
import { createServer } from './src/lexicons'
import { Hono } from 'hono'
type Env = { Bindings: {}; Variables: {} }
const xrpc = createServer()
xrpc.io.example.ping(async ({ auth, params, input, c }) => {
return {
encoding: 'application/json',
body: { pong: true },
}
})
const app = new Hono()
app.route('/', xrpc.createApp())
export default app
```
### Without generation (runtime registration)
```ts
import type { LexiconDoc } from '@atproto/lexicon'
import { Hono } from 'hono'
import { createXRPCHono } from '@evex-dev/xrpc-hono'
const lexicons: LexiconDoc[] = [
{
lexicon: 1,
id: 'io.example.ping',
defs: {
main: {
type: 'query',
parameters: { type: 'params', properties: { message: { type: 'string' } } },
output: { encoding: 'application/json' },
},
},
},
]
type Env = { Bindings: {}; Variables: {} }
const app = new Hono()
const xrpc = createXRPCHono(lexicons)
xrpc.addMethod('io.example.ping', async ({ auth, params, input, c }) => ({
encoding: 'application/json',
body: { pong: true },
}))
// With auth handler
xrpc.addMethod('io.example.ping', {
auth: async ({ ctx }) => ({ credentials: {}, artifacts: {} }),
handler: async ({ auth, params, input, c }) => ({
encoding: 'application/json',
body: { pong: true },
}),
})
app.route('/', xrpc.createApp())
export default app
```
## License
MIT — see the repository root LICENCE file for details.