Created
February 26, 2024 08:54
-
-
Save naxels/1ccee450dd6dda77d058a61445a2585b to your computer and use it in GitHub Desktop.
Elixir Req Jason decode options
This file contains hidden or 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
#!/usr/bin/env -S ERL_FLAGS=+B elixir | |
Mix.install([{:req, "~> 0.4.0"}]) | |
# the normal Req request which decodes to String | |
resp = Req.get!("https://dummyjson.com/products/1").body | |
IO.puts(resp["title"]) | |
IO.puts(resp["description"]) | |
# supplying the decode keyword list options: | |
resp = Req.get!("https://dummyjson.com/products/1", [decode_json: [keys: :atoms]]).body | |
IO.puts(resp.title) | |
IO.puts(resp.description) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment