I'm trying out the gleam programming language and I was hoping to do some simple things to get a feel for the language. One thing I wanted to try out was making HTTP request and I've gotten as far as:
import gleam/io
import gleam/http/request
import gleam/uri.{parse}
pub fn main() {
try uri = parse("https://lichess.org/api/puzzle/daily")
let req = request.from_uri(uri)
io.debug(req)
}
Which if I run outputs
{ok,{request,get,[],<<>>,https,<<"lichess.org">>,none,<<"/api/puzzle/daily">>,
none}}
This makes me think that the Request object is correctly being constructed, but I'm not seeing any requests being made. How do I fire off this request?
I've discovered over the course of writing out this question that the
gleam/httplibrary does not actually provide an HTTP client, which is what I was looking for. Likewise, it doesn't provide an HTTP server, however, all of the examples in the documentation forgleam/httpshow how to go about setting up a server with either gleam/cowboy or gleam/elli which made their relationship to the coregleam/httplibrary clear to me.The correct approach was to use an HTTP client library, for example gleam/hackney or httpc
I ended up with the following code:
Which correctly performs the request and prints the body