Let's fetch some data from an API using the requests module and use the json module to parse the response
Fetching data from the internet is relatively simple to do in Vortex. The standard library includes a module called requests that allows you to perform HTTP(S) actions. We'll use it to fetch some fake data from an API, parse it and write it to a file.
First we import all the modules/functions we need.
We define our headers that we'll be sending alongside our request. We then define the function that will retrieve our users from the randomuser API.
This function uses requests.get() to retrieve the data we need, sending the headers we defined earlier with it.
We then use json to parse the body of our response, and return it.
It's important to note that calling the random_users function will block the main thread. The requests module is not designed to be non-blocking. If you wanted it to be non-blocking, you will need to use a Future (import [Future] : future) to call the function in another thread.
Once we have our parsed data, we chain a few different functions to it to modify the output. The functions chain, filter and map are imported from the functional module.
We then join our strings together using the join function imported from string.
The last chain call writes the output to a file named people.txt using io.writef.
Lastly, we read the file we just created using io.readf and print the results to the console.