From 2fbed59e1ff372084ee6057be2ac9c6142f8f0a7 Mon Sep 17 00:00:00 2001 From: Tate Thurston Date: Wed, 2 Feb 2022 10:09:28 -0800 Subject: [PATCH] update node client docs (#117) Co-authored-by: Tate --- README.md | 12 ++++-------- examples/server-to-server/src/client.ts | 15 ++++++--------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 75744457..37a22dd7 100644 --- a/README.md +++ b/README.md @@ -165,16 +165,12 @@ import { nodeHttpTransport } from "twirpscript/dist/node"; import { MakeHat } from "../protos/haberdasher.pb"; client.baseURL = "http://localhost:8080"; + +// This is provided as a convenience for Node.js clients. If you provide `fetch` globally, this isn't necessary and your client can look identical to the browser client above. client.rpcTransport = nodeHttpTransport; -(async function () { - try { - const hat = await MakeHat({ inches: 12 }); - console.log(hat); - } catch (e) { - console.error(e); - } -})(); +const hat = await MakeHat({ inches: 12 }); +console.log(hat); ``` See a [Node.js client example](https://github.com/tatethurston/TwirpScript/blob/main/twirp-clientcompat/src/client-harness.ts#L11-L12). diff --git a/examples/server-to-server/src/client.ts b/examples/server-to-server/src/client.ts index 291e1b69..95d0d394 100644 --- a/examples/server-to-server/src/client.ts +++ b/examples/server-to-server/src/client.ts @@ -5,13 +5,10 @@ import { MakeHat, MakeHatJSON } from "./protos/haberdasher.pb"; client.baseURL = "http://localhost:8080"; client.rpcTransport = nodeHttpTransport; -(async function () { - try { - let hat = await MakeHat({ inches: 12 }); - console.log(hat); - hat = await MakeHatJSON({ inches: 11 }); - console.log(hat); - } catch (e) { - console.error(e); - } +(async () => { + const hat = await MakeHat({ inches: 12 }); + console.log(hat); + + const hatJSON = await MakeHatJSON({ inches: 11 }); + console.log(hatJSON); })();