Add working prototype for retrieving data

This commit is contained in:
Rasmus Rasmussen 2025-01-24 11:56:20 +01:00
parent 1bfccba59f
commit f47f2e738f
5 changed files with 41 additions and 10 deletions

1
.gitignore vendored
View File

@ -32,3 +32,4 @@
*.out *.out
*.app *.app
build/

View File

@ -1,6 +1,9 @@
program main program main
use WebServer, only: say_hello use WebServer, only: get_progress
use Greeter, only: say_hello
implicit none implicit none
call say_hello() call say_hello()
call get_progress()
end program main end program main

View File

@ -15,4 +15,6 @@ library = false
implicit-typing = false implicit-typing = false
implicit-external = false implicit-external = false
source-form = "free" source-form = "free"
[dependencies]
http = { git = "https://github.com/fortran-lang/http-client.git" }
stdlib = "*"

10
src/Greeter.f90 Normal file
View File

@ -0,0 +1,10 @@
module Greeter
implicit none
private
public :: say_hello
contains
subroutine say_hello
print *, "Hello, WebServer!"
end subroutine say_hello
end module Greeter

View File

@ -1,10 +1,25 @@
module WebServer module WebServer
implicit none use http, only : response_type, request
private implicit none
type(response_type) :: response
public :: say_hello private
contains
subroutine say_hello public :: get_progress
print *, "Hello, WebServer!" contains
end subroutine say_hello subroutine get_progress
end module WebServer ! Send a GET request to retrieve JSON data
response = request(url='https://proxy.rbwr.dk/progress')
! Check if the request was successful
if (.not. response%ok) then
print *, 'Error message:', response%err_msg
else
! Print the response details
print *, 'Response Code :', response%status_code
print *, 'Response Length :', response%content_length
print *, 'Response Method :', response%method
print *, 'Response Content :', response%content
end if
end subroutine get_progress
end module WebServer