Skip to content

Commit

Permalink
Make 'methods' the first argument to facilitate pure RPC es modules t…
Browse files Browse the repository at this point in the history
…hrough currying the 'respond' function
  • Loading branch information
timonson committed Apr 1, 2021
1 parent a20e088 commit 4415902
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
}
```

Expand Down
2 changes: 1 addition & 1 deletion server/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export type RespondOptions = {
};

export async function respond(
req: ServerRequest,
methods: ServerMethods,
req: ServerRequest,
options: RespondOptions = {},
) {
switch (options.proto) {
Expand Down

0 comments on commit 4415902

Please sign in to comment.