Skip to content

Instantly share code, notes, and snippets.

@naxels
Created February 26, 2024 08:54
Show Gist options
  • Save naxels/1ccee450dd6dda77d058a61445a2585b to your computer and use it in GitHub Desktop.
Save naxels/1ccee450dd6dda77d058a61445a2585b to your computer and use it in GitHub Desktop.
Elixir Req Jason decode options
#!/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