-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78ea1a4
commit 35ffbe0
Showing
1 changed file
with
27 additions
and
28 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 |
---|---|---|
@@ -1,39 +1,38 @@ | ||
app "simple2" | ||
packages { | ||
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br", | ||
json: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/lukewilliamboswell/roc-json/releases | ||
} | ||
imports [ | ||
cli.Stdout, | ||
cli.Task.{ await }, | ||
json.Core.{ jsonWithOptions }, | ||
"data.json" as requestBody : List U8, | ||
] | ||
provides [main] to cli | ||
app [main] { | ||
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br", | ||
json: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/lukewilliamboswell/roc-json/releases | ||
} | ||
|
||
import cli.Stdout | ||
import cli.Task | ||
import json.Core | ||
import "data.json" as requestBody : List U8 | ||
|
||
main = | ||
decoder = jsonWithOptions { } | ||
decoder = Core.jsonWithOptions {} | ||
|
||
decoded : Decode.DecodeResult (List DataRequest) | ||
decoded = Decode.fromBytesPartial requestBody decoder | ||
|
||
when decoded.result is | ||
Ok list -> | ||
_ <- Stdout.line "Successfully decoded list" |> Task.await | ||
rec1 = List.get list 0 | ||
when rec1 is | ||
Ok rec -> Stdout.line "Name of first person is: \(rec.lastname)" | ||
Err _ -> Stdout.line "Error occurred in List.get" | ||
Err TooShort -> Stdout.line "A TooShort error occurred" | ||
|
||
Ok list -> | ||
Stdout.line! "Successfully decoded list" | ||
|
||
when List.get list 0 is | ||
Ok rec -> Stdout.line! "Name of first person is: $(rec.lastname)" | ||
Err _ -> Stdout.line! "Error occurred in List.get" | ||
|
||
Err TooShort -> Stdout.line! "A TooShort error occurred" | ||
|
||
DataRequest : { | ||
id : I64, | ||
firstname : Str, | ||
lastname : Str, | ||
email : Str, | ||
gender : Str, | ||
ipaddress : Str, | ||
id : I64, | ||
firstname : Str, | ||
lastname : Str, | ||
email : Str, | ||
gender : Str, | ||
ipaddress : Str, | ||
} | ||
|
||
# => | ||
# Successfully decoded list | ||
# Name of first person is: Penddreth | ||
# Name of first person is: Penddreth |