An open API service indexing awesome lists of open source software.

https://github.com/nitindahiya-dev/get-request

Rust program that demonstrates making an HTTP GET request
https://github.com/nitindahiya-dev/get-request

get-request rust

Last synced: 24 days ago
JSON representation

Rust program that demonstrates making an HTTP GET request

Awesome Lists containing this project

README

          

# Simple HTTP Client in Rust with Error Handling


This repository contains a simple Rust program that demonstrates making an HTTP GET request using the `reqwest` crate, and handling potential errors using the `error_chain` crate.

## Features


  • Makes a GET request to `http://httpbin.org/get`.

  • Handles HTTP request errors and IO errors gracefully.

  • Prints the status, headers, and body of the HTTP response.


  • ## Prerequisites


  • [Rust](https://www.rust-lang.org/tools/install) (1.45.0 or later)


  • ## Usage

    1. Clone the repository:

    ```sh
    git clone https://github.com/your-username/rust-http-client.git
    cd rust-http-client
    ```

    2. Build the project:

    ```sh
    cargo build
    ```

    3. Run the project:

    ```sh
    cargo run
    ```

    ## Code Explanation

    The code uses the `error_chain` crate to manage errors and the `reqwest` crate to perform HTTP requests.


    ### Dependencies

    Add the following dependencies to your `Cargo.toml` file:

    ```toml
    [dependencies]
    reqwest = { version = "0.11", features = ["blocking"] }
    error-chain = "0.12.4"