HTTP Client

The http-client library is a high-level layer over libcurl for HTTP client requests that was developed during Google Summer of Code 2023. In comparison to the raw libcurl bindings, it offers a more user-friendly API to make HTTP requests in Fortran 2008 and newer. All common HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD) are supported. The library handles response headers, form data, file uploads, and basic authentication as well.


The client library depends on libcurl with additional development headers installed. On FreeBSD, run:

# pkg install ftp/curl

On Debian Linux, instead:

# apt-get install libcurl4 libcurl4-openssl-dev

The preferred method of linking the library is by using the Fortran Package Manager, and adding the dependency to the build manifest fpm.toml of the project:

http = { git = "" }
stdlib = "*"


The following basic example program simply starts a GET request to a given URL, retrieves the response, and prints the response details to standard output:

! app/main.f90
program main
    use :: http, only : response_type, request
    implicit none (type, external)
    type(response_type) :: response

    ! Send a GET request to retrieve plain-text file.
    response = request(url='')

    if (.not. response%ok) then
        print '("Error message: ", a)', response%err_msg
    end if

    ! Print the response.
    print '("Response Code:   ", a)',    response%status_code
    print '("Response Length: ", a)',    response%content_length
    print '("Response Method: ", a)',    response%method
    print '("Response Content:", /, a)', response%content
end program main

A minimal build manifest fpm.toml of the program may look like:

# fpm.toml
name = "get"

http = { git = "" }
stdlib = "*"

name = "get"
link = [ "curl" ]

The project name (get) can be chosen freely. The workspace directory of the example project must equal this specific structure:

In the last step, execute the Fortran Package Manager to build and run the program:

$ fpm build --profile release
$ fpm run

All dependencies will be downloaded and compiled automatically. The binary get is written to directory ./build/<compiler>/app/.

Fortran Libraries