forked from timonson/gentle_rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make 'methods' the first argument to facilitate pure RPC es modules t…
…hrough currying the 'respond' function
- Loading branch information
Showing
2 changed files
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,22 +17,22 @@ server argument or public error stacks. | |
import { serve } from "https://deno.land/[email protected]/http/server.ts" | ||
import { respond } from "https://deno.land/x/gentle_rpc/mod.ts" | ||
|
||
const s = serve("0.0.0.0:8000") | ||
console.log("listening on 0.0.0.0:8000") | ||
|
||
const server = serve("0.0.0.0:8000") | ||
const rpcMethods = { | ||
sayHello: (w: [string]) => `Hello ${w}`, | ||
callNamedParameters: ({ a, b, c }: { a: number; b: number; c: string }) => | ||
`${c} ${a * b}`, | ||
animalsMakeNoise: (noise: [string]) => | ||
animalsMakeNoise: (noise: string[]) => | ||
noise.map((el) => el.toUpperCase()).join(" "), | ||
} | ||
|
||
for await (const req of s) { | ||
console.log("listening on 0.0.0.0:8000") | ||
|
||
for await (const req of server) { | ||
// HTTP: | ||
await respond(req, rpcMethods) | ||
await respond(rpcMethods, req) | ||
// WebSockets: | ||
await respond(req, rpcMethods, { proto: "ws" }) | ||
await respond(rpcMethods, req, { proto: "ws" }) | ||
} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters