How to make HTTP Get Request using Golang and Rust?

Kanan Rahimov
2 min readApr 4, 2021

This code snippet is part of my local repository for demo and simple applications. I wanted to see a difference between Go and Rust code for the given task.

There are many ways to implement a simple HTTP Get in each language. Since I already have Golang experience, the code in Go took me a few minutes.

My initial goal for the Rust code was to write an HTTP Get using only the standard library. But surprisingly, the Rust code took me at least one hour, where at the end, I just took the code from the reqwest package and just simplified it for the text response.

Go implementation

package main

import (

func main() {

url := ""
resp, err := http.Get(url)
if err != nil {
log.Fatalf("Error fetching url %s: %v", url, err)

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error fetching url %s: %v", url, err)

log.Println("Response: ")

Rust implementation

For the Rust implementation, I am going to use reqwest package. That's why we need to initialize a project environment using the following commands:

cargo init

Then edit content of the Cargo.toml and add reqwest dependency:

reqwest = { version = "0.11", features = ["blocking", "json"] }

I will use blocking call API.

Here is the actual Rust code for fetching webpage’s content via HTTP GET request:

fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::blocking::get("")?
println!("{:#?}", resp);

If you are also a newbie in Rust as myself, you can run this code by executing the following command:

cargo run

Originally published at on April 4, 2021.