aboutsummaryrefslogtreecommitdiff
path: root/examples/haberdasher/haberdasherclient.nim
diff options
context:
space:
mode:
Diffstat (limited to 'examples/haberdasher/haberdasherclient.nim')
-rw-r--r--examples/haberdasher/haberdasherclient.nim25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/haberdasher/haberdasherclient.nim b/examples/haberdasher/haberdasherclient.nim
new file mode 100644
index 0000000..d402356
--- /dev/null
+++ b/examples/haberdasher/haberdasherclient.nim
@@ -0,0 +1,25 @@
+import os
+import strformat
+import strutils
+
+import service_pb
+import service_twirp
+
+if paramCount() != 1:
+ echo("usage: " & getAppFilename() & " <size>")
+ quit(QuitFailure)
+
+var size = newtwirp_example_haberdasher_Size()
+try:
+ size.inches = parseInt(paramStr(1)).int32
+except:
+ echo("invalid size")
+ quit(QuitFailure)
+
+let client = newHaberdasherClient("http://localhost:8080")
+
+try:
+ let hat = MakeHat(client, size)
+ echo(&"I have a nice new hat: {hat.inches} inch {hat.color} {hat.name}")
+except Exception as exc:
+ echo(&"oh no: {exc.msg}")