Stream: beginners

Topic: basic-cli http-get-json example


view this post on Zulip Jacob Cole (Aug 11 2024 at 17:27):

Hi all. I’m trying to get the basic-cli http-get-json example to work. My code (only slightly modified):

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br",
    json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.10.0/KbIfTNbxShRX1A1FgXei1SpO5Jn8sgP6HP6PXbi-xyA.tar.br",
}

import pf.Http
import pf.Task exposing [Task]
import pf.Stdout
import json.Json

# HTTP GET request with easy decoding to json

main : Task {} [Exit I32 Str]
main =
    run
    |> Task.mapErr (\err -> Exit 1 (Inspect.toStr err))

run : Task {} _
run =
    # Easy decoding/deserialization of { "foo": "something" } into a Roc var
    { title } = Http.get! "https://jsonplaceholder.typicode.com/todos/1" Json.utf8

    Stdout.line! "The json I received was: { title: \"$(title)\" }"

I used the Nix flake with NixOS on WSL (though a Nix beginner also).

nix flake init --template github:roc-lang/roc#simple --refresh

I get these outputs.

$ roc run --linker=legacy
free(): invalid pointer
Aborted
$ roc run --linker=legacy
Segmentation fault

Am I doing anything wrong or is this a Roc or platform bug? With more complex code I would think roc check false negatives are possible too. Are they or not really?

Is there a recommended path (os, platform, etc) to use to have the most stable experience?

Overall love the ideas of Roc so far :)

view this post on Zulip Brendan Hansknecht (Aug 12 2024 at 01:06):

I don't fully understand all of the flake wiring, but what do you get from roc version?

view this post on Zulip Brendan Hansknecht (Aug 12 2024 at 01:07):

My guess is that your version of the compiler is too new for basic-cli version 0.12.0. We recently had some breaking changes that make platform and compiler versioning a bit more finicky.

view this post on Zulip Brendan Hansknecht (Aug 12 2024 at 01:08):

Is there a recommended path

Linux and mac are most tested. WSL should work though.

view this post on Zulip Brendan Hansknecht (Aug 12 2024 at 01:10):

From some quick local testing, you either need to upgrade your basic-cli version or downgrade your roc version.

view this post on Zulip Brendan Hansknecht (Aug 12 2024 at 01:13):

The pre-release basic-cli 0.13.0 should work with current roc built from source. Or you can downgrade roc to one of the -latest releases. I think nix is equivalent to the -TESTING release.

view this post on Zulip Brendan Hansknecht (Aug 12 2024 at 01:14):

@Anton is there a way for us to exposing testing and latest through nix directly?

nix flake init --template github:roc-lang/roc#simple-testing --refresh or something? Not actually sure how the # and versioning works here.

view this post on Zulip Jacob Cole (Aug 12 2024 at 01:59):

roc version gives roc built-from-source
basic-cli 0.13.0 indeed works. Thanks!

view this post on Zulip Anton (Aug 12 2024 at 08:18):

@Anton is there a way for us to exposing testing and latest through nix directly?

I think that's possible but also quite difficult. You can however decompress a latest or testing release, and you'll see the commit it used, you can use that commit in a nix flake like this:

inputs = { roc.url = "github:roc-lang/roc?rev=COMMIT"; };

Last updated: Jul 05 2025 at 12:14 UTC