diff --git a/index.html b/index.html
index be3d80e..bed55db 100644
--- a/index.html
+++ b/index.html
@@ -189,12 +189,9 @@
Projects using http-client
An fpm example project that displays the latest xkcd comic inside an X window.
As a limitation, only images in PNG format are supported.
The alt text will be printed to console.
-
-foropenai: A Fortran library to access the OpenAI API.
-
-
-fortelegram-bot: An Example of simple telegram bot
-
+foropenai: A Fortran library to access the OpenAI API.
+fortelegram-bot: An Example of simple telegram bot
+forcompile: A Fortran library to access the Compiler Explorer API.
If you're using http-client in your Fortran project and would like to be
included on this list, we welcome you to contribute by creating a pull request
@@ -338,7 +335,7 @@
Derived Types
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/interface/client_type.html b/interface/client_type.html
index d613f41..e9a8c5d 100644
--- a/interface/client_type.html
+++ b/interface/client_type.html
@@ -267,7 +267,7 @@
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/interface/request.html b/interface/request.html
index 425eee0..6c28584 100644
--- a/interface/request.html
+++ b/interface/request.html
@@ -375,7 +375,7 @@
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/lists/files.html b/lists/files.html
index d21dc71..47337f1 100644
--- a/lists/files.html
+++ b/lists/files.html
@@ -121,7 +121,7 @@ Source Files
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/lists/modules.html b/lists/modules.html
index 62f6eef..fed4b1e 100644
--- a/lists/modules.html
+++ b/lists/modules.html
@@ -122,7 +122,7 @@ Modules
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/lists/procedures.html b/lists/procedures.html
index 6db8e81..aea932d 100644
--- a/lists/procedures.html
+++ b/lists/procedures.html
@@ -143,7 +143,7 @@ Procedures
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/lists/types.html b/lists/types.html
index 334dc79..acb1d41 100644
--- a/lists/types.html
+++ b/lists/types.html
@@ -112,7 +112,7 @@ Derived Types
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/module/http.html b/module/http.html
index c4ec06e..98c3703 100644
--- a/module/http.html
+++ b/module/http.html
@@ -162,10 +162,10 @@ Uses
@@ -226,7 +226,7 @@ Contents
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/module/http_client.html b/module/http_client.html
index 65732ed..716a961 100644
--- a/module/http_client.html
+++ b/module/http_client.html
@@ -222,12 +222,12 @@ Uses
@@ -1538,7 +1538,7 @@ Arguments
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/module/http_pair.html b/module/http_pair.html
index 09930d6..7e3c906 100644
--- a/module/http_pair.html
+++ b/module/http_pair.html
@@ -575,7 +575,7 @@ Arguments
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/module/http_request.html b/module/http_request.html
index ea60b4c..180ca73 100644
--- a/module/http_request.html
+++ b/module/http_request.html
@@ -189,8 +189,8 @@ Uses
-
@@ -406,7 +406,7 @@ Components
-
+
character(len=:),
|
public, |
@@ -423,7 +423,7 @@ Components
-
+
character(len=:),
|
public, |
@@ -440,7 +440,7 @@ Components
-
+
character(len=:),
|
public, |
@@ -457,7 +457,7 @@ Components
-
+
integer,
|
public |
@@ -474,7 +474,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -491,7 +491,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -508,7 +508,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -525,7 +525,7 @@ Components
-
+
integer(kind=int64),
|
public |
@@ -542,7 +542,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -588,7 +588,7 @@ Components
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/module/http_response.html b/module/http_response.html
index dab84bf..5b25f01 100644
--- a/module/http_response.html
+++ b/module/http_response.html
@@ -184,8 +184,8 @@ Uses
-
@@ -521,7 +521,7 @@
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/module/http_version.html b/module/http_version.html
index bd9ba13..741fdb9 100644
--- a/module/http_version.html
+++ b/module/http_version.html
@@ -304,7 +304,7 @@ Variables
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/append_pair.html b/proc/append_pair.html
index 6750867..e20eb71 100644
--- a/proc/append_pair.html
+++ b/proc/append_pair.html
@@ -315,7 +315,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/client_get_response.html b/proc/client_get_response.html
index 8dde2e0..5f1968d 100644
--- a/proc/client_get_response.html
+++ b/proc/client_get_response.html
@@ -348,7 +348,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/client_header_callback.html b/proc/client_header_callback.html
index cad6c54..e6d1468 100644
--- a/proc/client_header_callback.html
+++ b/proc/client_header_callback.html
@@ -363,7 +363,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/client_response_callback.html b/proc/client_response_callback.html
index b0d775b..fb4ba4a 100644
--- a/proc/client_response_callback.html
+++ b/proc/client_response_callback.html
@@ -368,7 +368,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/get_pair_value.html b/proc/get_pair_value.html
index 16281c6..f981b50 100644
--- a/proc/get_pair_value.html
+++ b/proc/get_pair_value.html
@@ -315,7 +315,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/header_value.html b/proc/header_value.html
index d45c748..ce27215 100644
--- a/proc/header_value.html
+++ b/proc/header_value.html
@@ -300,7 +300,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/new_client.html b/proc/new_client.html
index a2009a6..a083372 100644
--- a/proc/new_client.html
+++ b/proc/new_client.html
@@ -277,7 +277,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/new_request.html b/proc/new_request.html
index 41bad41..68bd4ca 100644
--- a/proc/new_request.html
+++ b/proc/new_request.html
@@ -186,7 +186,7 @@ Arguments
-
+
character(len=*),
|
intent(in) |
@@ -201,7 +201,7 @@ Arguments
-
+
integer,
|
intent(in), |
@@ -217,7 +217,7 @@ Arguments
-
+
type(pair_type),
|
intent(in), |
@@ -232,7 +232,7 @@ Arguments
-
+
character(len=*),
|
intent(in), |
@@ -247,7 +247,7 @@ Arguments
-
+
type(pair_type),
|
intent(in), |
@@ -262,7 +262,7 @@ Arguments
-
+
type(pair_type),
|
intent(in), |
@@ -277,7 +277,7 @@ Arguments
-
+
integer,
|
intent(in), |
@@ -292,7 +292,7 @@ Arguments
-
+
type(pair_type),
|
intent(in), |
@@ -459,7 +459,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/pair_has_name.html b/proc/pair_has_name.html
index 2e03410..6ded9a6 100644
--- a/proc/pair_has_name.html
+++ b/proc/pair_has_name.html
@@ -307,7 +307,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/prepare_form_encoded_str.html b/proc/prepare_form_encoded_str.html
index d0373a2..b90da4e 100644
--- a/proc/prepare_form_encoded_str.html
+++ b/proc/prepare_form_encoded_str.html
@@ -212,7 +212,7 @@ Arguments
Return Value
-
+
character(len=:), allocatable
@@ -316,7 +316,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/prepare_request_header_ptr.html b/proc/prepare_request_header_ptr.html
index 5030f98..5a9d7cc 100644
--- a/proc/prepare_request_header_ptr.html
+++ b/proc/prepare_request_header_ptr.html
@@ -310,7 +310,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/set_auth.html b/proc/set_auth.html
index 14225ca..e8014df 100644
--- a/proc/set_auth.html
+++ b/proc/set_auth.html
@@ -305,7 +305,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/set_body.html b/proc/set_body.html
index b08f084..d490dda 100644
--- a/proc/set_body.html
+++ b/proc/set_body.html
@@ -465,7 +465,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/set_method.html b/proc/set_method.html
index 9b90f58..3c8a70b 100644
--- a/proc/set_method.html
+++ b/proc/set_method.html
@@ -199,7 +199,7 @@ Arguments
-
+
integer,
|
intent(in) |
@@ -341,7 +341,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/set_postfields.html b/proc/set_postfields.html
index 4bbbe26..5ec1877 100644
--- a/proc/set_postfields.html
+++ b/proc/set_postfields.html
@@ -197,7 +197,7 @@ Arguments
-
+
character(len=*),
|
intent(in), |
@@ -300,7 +300,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/proc/set_timeout.html b/proc/set_timeout.html
index c40dd3b..8ad5275 100644
--- a/proc/set_timeout.html
+++ b/proc/set_timeout.html
@@ -194,7 +194,7 @@ Arguments
-
+
integer(kind=int64),
|
intent(in) |
@@ -301,7 +301,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/search.html b/search.html
index 260a151..a1d4113 100644
--- a/search.html
+++ b/search.html
@@ -119,7 +119,7 @@ Search Results
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/sourcefile/http.f90.html b/sourcefile/http.f90.html
index 3c29480..e887f9f 100644
--- a/sourcefile/http.f90.html
+++ b/sourcefile/http.f90.html
@@ -252,7 +252,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/sourcefile/http_client.f90.html b/sourcefile/http_client.f90.html
index 67511c7..f1b0ab8 100644
--- a/sourcefile/http_client.f90.html
+++ b/sourcefile/http_client.f90.html
@@ -847,7 +847,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/sourcefile/http_pair.f90.html b/sourcefile/http_pair.f90.html
index 5b1d578..c4e90a5 100644
--- a/sourcefile/http_pair.f90.html
+++ b/sourcefile/http_pair.f90.html
@@ -362,7 +362,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/sourcefile/http_request.f90.html b/sourcefile/http_request.f90.html
index 30d299a..55c75f2 100644
--- a/sourcefile/http_request.f90.html
+++ b/sourcefile/http_request.f90.html
@@ -283,7 +283,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/sourcefile/http_response.f90.html b/sourcefile/http_response.f90.html
index ebc785e..364d1cd 100644
--- a/sourcefile/http_response.f90.html
+++ b/sourcefile/http_response.f90.html
@@ -293,7 +293,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/sourcefile/http_version.f90.html b/sourcefile/http_version.f90.html
index caa34be..1fae909 100644
--- a/sourcefile/http_version.f90.html
+++ b/sourcefile/http_version.f90.html
@@ -248,7 +248,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/tipuesearch/tipuesearch_content.js b/tipuesearch/tipuesearch_content.js
index ad22bc1..f5ee7a6 100644
--- a/tipuesearch/tipuesearch_content.js
+++ b/tipuesearch/tipuesearch_content.js
@@ -1 +1 @@
-var tipuesearch = {"pages":[{"title":" HTTP ","text":"HTTP http-client http-client is Fortran library to make HTTP requests.\nIt simplifies interacting with web services by providing a high-level and\nuser-friendly interface. Features HTTP request methods: GET : Retrieve data from the server. POST : Create new data the server. PUT : Replace an existing resource on the server. DELETE : Delete a resource from the server. PATCH : Partially update a resource on the server. HEAD : Get response headers without the response content. Supported data types: URL encoded fields HTTP form data File uploads Response handling: Retrieve response body (content). Get the HTTP status code returned by the server. Access response headers. Setting custom request headers Error handling with informative error messages Setting request timeouts Basic HTTP authentication Installation Before building the http-client library, ensure that you have the necessary\ndependencies installed. On Ubuntu, you need to install the curl development\nheaders. Use the following command: sudo apt install -y libcurl4-openssl-dev To use http-client as a dependency in your fpm project, add the following to\nyour the fpm.toml file of your package: [dependencies] http = { git = \"https://github.com/fortran-lang/http-client.git\" } stdlib = \"*\" Example use The following example demonstrates how to use http-client to make a simple GET request and process the response: program simple_get use http , only : response_type , request implicit none type ( response_type ) :: response ! Send a GET request to retrieve JSON data response = request ( url = 'https://jsonplaceholder.typicode.com/todos/1' ) ! 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 program simple_get Ouptut: Response Code : 200\n Response Length : 83\n Response Method : GET\n Response Content : {\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n} In this example, we make a GET request to the URL\nhttps://jsonplaceholder.typicode.com/todos/1 to retrieve JSON data.\nIf the request is successful, we print the response code, content length,\nmethod, and content. If the request fails, we print the error message. Getting Started Guides To begin your journey with our package, dive into the comprehensive tutorial\navailable here: tutorial.md . Projects using http-client github-org-analyzer :\nAn example mini-project to demonstrate the use of http-client by downloading\nand parsing data from the GitHub API. fortran-xkcd :\nAn fpm example project that displays the latest xkcd comic inside an X window.\nAs a limitation, only images in PNG format are supported.\nThe alt text will be printed to console. foropenai : A Fortran library to access the OpenAI API. fortelegram-bot : An Example of simple telegram bot If you're using http-client in your Fortran project and would like to be\nincluded on this list, we welcome you to contribute by creating a pull request\n(PR) and adding your project details. Contributing to project Thank you for your interest in http-client! Contributions from the community\nare esential for improving the package. This section provides a guide on how to\nget the code, build the library, and run examples and tests. Get the code To get started, follow these steps: Clone the repository using Git: git clone https://github.com/fortran-lang/http-client\ncd http-client Prerequisites Before building the library, ensure that you have the necessary dependencies\ninstalled. On Ubuntu, you need to install the curl development headers.\nUse the following command: sudo apt install -y libcurl4-openssl-dev Build the library http-client uses fpm as the build system. Make sure you have fpm-0.8.x or\nlater installed. To build the library, run the following command within the\nproject directory: fpm build Run examples http-client provides example programs that demonstrate its use. To run the\nexamples, use the following command: fpm run --example Executing this command will execute the example programs, allowing you to see\nthe package in action and understand how to utilize its features. Run tests http-client includes a test suite to ensure its functionality is working as\nexpected. To run the tests, type: fpm test Running the tests will validate the behavior of the package and help identify\nany issues or regressions. Generating API Documentation Before generating API documentation, ensure that you have FORD installed on your system . Once FORD is set up, execute the following command to build the API documentation: ford ford.md Supported compilers http-client is known to work with the following compilers: GFortran 11 & 12 (tested in CI) Intel OneAPI ifx v2023.1.0 and ifort classic v2021.9.0 Contributing guidelines When contributing to the http Fortran package, please keep the following guidelines in mind: Before making any substantial changes, it is recommended to open an issue to discuss the proposed changes and ensure they align with the project's goals. Fork the repository and create a new branch for your contribution. Ensure that your code adheres to the existing coding style and follows good software engineering practices. Write clear and concise commit messages. Make sure to test your changes and ensure they do not introduce regressions or break existing functionality. Submit a pull request with your changes, providing a clear explanation of the problem you are solving and the approach you have taken. We appreciate your contributions and look forward to your valuable input in improving http-client. Happy coding!👋 Developer Info Rajkumar Dongre Just Love to build Things 🛠️","tags":"home","loc":"index.html"},{"title":"response_type – HTTP ","text":"type, public :: response_type Representing an HTTP response . Contents Variables url content method err_msg status_code content_length ok header Type-Bound Procedures header_value Source Code response_type Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: content The content of the response. character(len=:), public, allocatable :: method The HTTP method of the request. character(len=:), public, allocatable :: err_msg The Error message if the response was not successful. integer, public :: status_code = 0 The HTTP status code of the response integer(kind=int64), public :: content_length = 0 length of the response content. logical, public :: ok = .true. true if the response was successful else false. type( pair_type ), public, allocatable :: header (:) An Array of response headers. Type-Bound Procedures procedure, public, :: header_value private pure function header_value (this, name) result(val) This function is used to retrieve the value of a response header. \nIt takes the response header name as input and returns the corresponding header value . Arguments Type Intent Optional Attributes Name class( response_type ), intent(in) :: this An object representing the HTTP response. character(len=*), intent(in) :: name This refers to the name of the header for which we want to retrieve the value. Return Value character(len=:), allocatable This denotes the value of the specified header name. Source Code type :: response_type !!> Representing an **HTTP `response`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: content !! The content of the response. character ( len = :), allocatable :: method !! The HTTP method of the request. character ( len = :), allocatable :: err_msg !! The Error message if the response was not successful. integer :: status_code = 0 !! The HTTP status code of the response integer ( kind = int64 ) :: content_length = 0 !! length of the response content. logical :: ok = . true . !! true if the response was successful else false. type ( pair_type ), allocatable :: header (:) !! An Array of response headers. contains procedure :: header_value end type response_type","tags":"","loc":"type/response_type.html"},{"title":"request_type – HTTP ","text":"type, public :: request_type Representing an HTTP request . Contents Variables url data form_encoded_str method header form file timeout auth Source Code request_type Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: data The data to be send with request character(len=:), public, allocatable :: form_encoded_str The URL-encoded form data. integer, public :: method The HTTP method of the request. type( pair_type ), public, allocatable :: header (:) An Array of request headers. type( pair_type ), public, allocatable :: form (:) An array of fields in an HTTP form. type( pair_type ), public, allocatable :: file Used to store information about files to be sent in HTTP requests. integer(kind=int64), public :: timeout Timeout value for the request in seconds . type( pair_type ), public, allocatable :: auth Stores the username and password for Authentication Source Code type :: request_type !! Representing an **HTTP `request`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: data !! The data to be send with request character ( len = :), allocatable :: form_encoded_str !! The URL-encoded form data. integer :: method !! The HTTP method of the request. type ( pair_type ), allocatable :: header (:) !! An Array of request headers. type ( pair_type ), allocatable :: form (:) !! An array of fields in an HTTP form. type ( pair_type ), allocatable :: file !! Used to store information about files to be sent in HTTP requests. integer ( kind = int64 ) :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), allocatable :: auth !! Stores the username and password for Authentication end type request_type","tags":"","loc":"type/request_type.html"},{"title":"client_type – HTTP ","text":"type, private :: client_type A derived type, responsible for making actual HTTP request using\nfortran-curl at backend. Contents Variables request Constructor client_type Type-Bound Procedures client_get_response Source Code client_type Components Type Visibility Attributes Name Initial type( request_type ), public :: request Constructor private interface client_type Interface for new_client function. private function new_client (request) result(client) This is the constructor for the client_type derived type. Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. Type-Bound Procedures procedure, public, :: client_get_response private function client_get_response (this) result(response) This function sends an HTTP request to a server using the fortran-curl package \nand stores the server's response in a response_type object. Arguments Type Intent Optional Attributes Name class( client_type ), intent(inout) :: this Contains the HTTP request to send. Return Value type( response_type ), target Contains the server's response . Source Code type :: client_type !!> A derived type, responsible for making **actual HTTP `request`** using !!> fortran-curl at backend. type ( request_type ) :: request contains procedure :: client_get_response end type client_type","tags":"","loc":"type/client_type.html"},{"title":"pair_type – HTTP ","text":"type, public :: pair_type A derived type use to store a name-value pair . It is used in many instances like: Storing request and response headers : name to represent the header name. value to represent the header value. Representing fields in a url-encoded HTTP form : name to represent the form field name. value to represent the form field value. Storing information about the file to upload: name to represent the name of the file. value to represent the path of the file on the local system. Storing authentication detail, require to authenticate the request. name to represent the username value to represent the password Contents Variables name value Source Code pair_type Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: name Name (key) character(len=:), public, allocatable :: value Value Source Code type :: pair_type !!> A derived type use to store a **name-value pair**. !!>____ !!>It is used in many instances like: !!> !!>1. Storing request and response `headers`: !!> - `name` to represent the header name. !!> - `value` to represent the header value. !!> !!>2. Representing fields in a url-encoded **HTTP `form`**: !!> - `name` to represent the form field name. !!> - `value` to represent the form field value. !!> !!>3. Storing information about the `file` to upload: !!> - `name` to represent the name of the file. !!> - `value` to represent the path of the file on the local system. !!> !!>4. Storing authentication detail, require to authenticate the request. !!> - `name` to represent the **username** !!> - `value` to represent the **password** character (:), allocatable :: name !! Name (key) character (:), allocatable :: value !! Value end type pair_type","tags":"","loc":"type/pair_type.html"},{"title":"header_value – HTTP","text":"private pure function header_value(this, name) result(val) This function is used to retrieve the value of a response header. \nIt takes the response header name as input and returns the corresponding header value . Type Bound response_type Arguments Type Intent Optional Attributes Name class( response_type ), intent(in) :: this An object representing the HTTP response. character(len=*), intent(in) :: name This refers to the name of the header for which we want to retrieve the value. Return Value character(len=:), allocatable This denotes the value of the specified header name. Contents Source Code header_value Source Code pure function header_value ( this , name ) result ( val ) !!> This function is used to retrieve the `value` of a response header. !!> It takes the response header `name` as input and returns the corresponding !!> **header value**. class ( response_type ), intent ( in ) :: this !! An object representing the HTTP response. character ( * ), intent ( in ) :: name !! This refers to the name of the header for which we want to retrieve the value. character (:), allocatable :: val !! This denotes the value of the specified header name. val = get_pair_value ( this % header , name ) end function header_value","tags":"","loc":"proc/header_value.html"},{"title":"new_request – HTTP","text":"private function new_request(url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Note : If the header argument is not provided, default user-agent header is set to http-client/0.1 . Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response . Contents Source Code new_request Source Code function new_request ( url , method , header , data , form , file , timeout , auth ) result ( response ) !!> This function create a `request_type` object and populates it. !!> The function returns the `response_type` object containing the !!> **server's response**. !!____ !!> #### Note : !!> If the `header` argument is not provided, **default `user-agent` !!> header is set to `http-client/0.1`**. integer , intent ( in ), optional :: method !! Specifies the HTTP `method` to use for the request. !! The **default value is 1**, which corresponds to the **`HTTP_GET`** method. character ( len =* ), intent ( in ) :: url !! Specifies the **`URL`** of the server. character ( len =* ), intent ( in ), optional :: data !! Specifies the **`data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: header (:) !! Specifies the **request `headers`** that need to be sent to the server. type ( pair_type ), intent ( in ), optional :: form (:) !! Specifies the **`form data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: file !! Specifies the **`file`** that needs to be sent to the server. integer , intent ( in ), optional :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), intent ( in ), optional :: auth !! stores the `username` and `password` for **`authentication`** purposes. type ( response_type ) :: response !! Stores the server's **`response`**. type ( request_type ) :: request type ( client_type ) :: client integer :: i ! setting request url request % url = url ! Set default HTTP method. request % method = optval ( method , 1 ) ! Set request header if ( present ( header )) then request % header = header ! Set default request headers. if (. not . pair_has_name ( header , 'user-agent' )) then call append_pair ( request % header , 'user-agent' , 'http-client/' // VERSION_STRING ) end if else ! Set default request headers. request % header = [ pair_type ( 'user-agent' , 'http-client/' // VERSION_STRING )] end if ! setting the request data to be send if ( present ( data )) then request % data = data end if ! setting request form if ( present ( form )) then request % form = form end if ! setting request file if ( present ( file )) then request % file = file end if ! Set request timeout. request % timeout = optval ( timeout , - 1 ) ! setting username and password for Authentication if ( present ( auth )) then request % auth = auth end if ! Populates the response client = client_type ( request = request ) response = client % client_get_response () end function new_request","tags":"","loc":"proc/new_request.html"},{"title":"new_client – HTTP","text":"private function new_client(request) result(client) This is the constructor for the client_type derived type. Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. Contents Source Code new_client Source Code function new_client ( request ) result ( client ) !!> This is the constructor for the `client_type` derived type. type ( request_type ), intent ( in ) :: request !! Specifies the **HTTP `request`** to send. type ( client_type ) :: client !! A `client_type` object containing the `request` field set to the input `request` object. client % request = request end function new_client","tags":"","loc":"proc/new_client.html"},{"title":"client_get_response – HTTP","text":"private function client_get_response(this) result(response) This function sends an HTTP request to a server using the fortran-curl package \nand stores the server's response in a response_type object. Type Bound client_type Arguments Type Intent Optional Attributes Name class( client_type ), intent(inout) :: this Contains the HTTP request to send. Return Value type( response_type ), target Contains the server's response . Contents Source Code client_get_response Source Code function client_get_response ( this ) result ( response ) !!> This function sends an HTTP `request` to a server using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package !!> and stores the server's response in a `response_type` !!> object. class ( client_type ), intent ( inout ) :: this !! Contains the HTTP `request` to send. type ( response_type ), target :: response !! Contains the **server's response**. type ( c_ptr ) :: curl_ptr , header_list_ptr integer :: rc , i curl_ptr = c_null_ptr header_list_ptr = c_null_ptr response % url = this % request % url curl_ptr = curl_easy_init () if (. not . c_associated ( curl_ptr )) then response % ok = . false . response % err_msg = \"The initialization of a new easy handle using the 'curl_easy_init()'& & function failed. This can occur due to insufficient memory available in the system. & & Additionally, if libcurl is not installed or configured properly on the system\" return end if ! setting request URL rc = curl_easy_setopt ( curl_ptr , CURLOPT_URL , this % request % url ) ! setting request method rc = set_method ( curl_ptr , this % request % method , response ) ! setting request timeout rc = set_timeout ( curl_ptr , this % request % timeout ) ! setting request body rc = set_body ( curl_ptr , this % request ) ! setting request authentication rc = set_auth ( curl_ptr , this % request ) ! prepare headers for curl call prepare_request_header_ptr ( header_list_ptr , this % request % header ) ! setting request header rc = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPHEADER , header_list_ptr ); ! setting callback for writing received data rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEFUNCTION , c_funloc ( client_response_callback )) ! setting response content pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEDATA , c_loc ( response )) ! setting callback for writing received headers rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERFUNCTION , c_funloc ( client_header_callback )) ! setting response header pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERDATA , c_loc ( response )) ! Send request. rc = curl_easy_perform ( curl_ptr ) if ( rc /= CURLE_OK ) then response % ok = . false . response % err_msg = curl_easy_strerror ( rc ) end if ! setting response status_code rc = curl_easy_getinfo ( curl_ptr , CURLINFO_RESPONSE_CODE , response % status_code ) call curl_easy_cleanup ( curl_ptr ) end function client_get_response","tags":"","loc":"proc/client_get_response.html"},{"title":"prepare_form_encoded_str – HTTP","text":"private function prepare_form_encoded_str(curl_ptr, request) result(form_encoded_str) This subroutine converts the request%form into a URL-encoded name-value \nstring and returns it. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. type( request_type ), intent(inout) :: request The HTTP request to send, which includes the form data to be encoded. Return Value character(len=:), allocatable Stores the URL Encoded string . Contents Source Code prepare_form_encoded_str Source Code function prepare_form_encoded_str ( curl_ptr , request ) result ( form_encoded_str ) !!> This subroutine converts the `request%form` into a **URL-encoded name-value !!> string** and returns it. ! This subroutine takes a request object containing a list of name-value pairs ! representing the form data. It iterates over the list and URL-encodes each ! name and value using the curl_easy_escape function, which replaces special ! characters with their corresponding escape sequences. ! The encoded name-value pairs are concatenated into a single string, separated ! by '&' characters. The resulting string is returned type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. type ( request_type ), intent ( inout ) :: request !! The HTTP `request` to send, which includes the `form` data to be encoded. character (:), allocatable :: form_encoded_str !! Stores the **URL Encoded string**. integer :: i if ( allocated ( request % form )) then do i = 1 , size ( request % form ) if (. not . allocated ( form_encoded_str )) then form_encoded_str = curl_easy_escape ( curl_ptr , request % form ( i )% name , & len ( request % form ( i )% name )) // '=' // curl_easy_escape ( curl_ptr , & request % form ( i )% value , len ( request % form ( i )% value )) else form_encoded_str = form_encoded_str // '&' // & curl_easy_escape ( curl_ptr , request % form ( i )% name , len ( request % form ( i )% name ))& // '=' // curl_easy_escape ( curl_ptr , request % form ( i )% value , len ( request % form ( i )% value )) end if end do end if end function prepare_form_encoded_str","tags":"","loc":"proc/prepare_form_encoded_str.html"},{"title":"set_method – HTTP","text":"private function set_method(curl_ptr, method, response) result(status) This function sets the HTTP method for the request. The method argument can take one of the following values: HTTP_GET , HTTP_HEAD , HTTP_POST , HTTP_PUT , HTTP_DELETE , HTTP_PATCH . If any other value is provided, an error will be thrown . Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. integer, intent(in) :: method Specifies the HTTP method to use. type( response_type ), intent(out) :: response The HTTP response from the server. Return Value integer The status of setting HTTP method. Contents Source Code set_method Source Code function set_method ( curl_ptr , method , response ) result ( status ) !!> This function sets the **HTTP `method`** for the request. !!____ !!#### **The `method` argument can take one of the following values:** !!> `HTTP_GET`, `HTTP_HEAD`, `HTTP_POST`, `HTTP_PUT`, `HTTP_DELETE`, !!> `HTTP_PATCH`. If any other value is provided, an **error will be thrown**. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. integer , intent ( in ) :: method !! Specifies the HTTP `method` to use. type ( response_type ), intent ( out ) :: response !! The HTTP `response` from the server. integer :: status !! The `status` of setting HTTP method. select case ( method ) case ( 1 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'GET' ) response % method = 'GET' case ( 2 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'HEAD' ) response % method = 'HEAD' case ( 3 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'POST' ) response % method = 'POST' case ( 4 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PUT' ) response % method = 'PUT' case ( 5 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'DELETE' ) response % method = 'DELETE' case ( 6 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PATCH' ) response % method = 'PATCH' case default error stop 'Method argument can be either HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_PATCH' end select end function set_method","tags":"","loc":"proc/set_method.html"},{"title":"set_timeout – HTTP","text":"private function set_timeout(curl_ptr, timeout) result(status) This function sets the timeout value (in seconds) . If the timeout value is less than zero , it is ignored and a success status is returned. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. integer(kind=int64), intent(in) :: timeout Timeout seconds for request. Return Value integer Status code indicating whether the operation was successful. Contents Source Code set_timeout Source Code function set_timeout ( curl_ptr , timeout ) result ( status ) !!> This function sets the `timeout` value **(in seconds)**. !!> !!> If the `timeout` value is **less than zero**, it is ignored and a success status is returned. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. integer ( kind = int64 ), intent ( in ) :: timeout !! `Timeout` seconds for request. integer :: status !! `Status code` indicating whether the operation was successful. if ( timeout < 0 ) then status = 0 else ! setting the maximum time allowed for the connection to established.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_CONNECTTIMEOUT , timeout ) ! setting maximum time allowed for transfer operation.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_TIMEOUT , timeout ) end if end function set_timeout","tags":"","loc":"proc/set_timeout.html"},{"title":"set_body – HTTP","text":"private function set_body(curl_ptr, request) result(status) The function sets the request body . This function determines and set the type of data to include in the request body based on the inputs provided to the request() procedure. The function handles different combinations of data , file , and form members \nto decide the content and the default header for the request body. If data member is provided, it takes the highest priority and is sent as the \nbody of the request. Any other provided file or form members will be ignored, \nand only the data member will be included in the request body. If only the file member is provided, the file is sent as the body of the request. \nIf no Content-type header is provided, a default Content-type header with value multipart/form-data will be set. If only the form member is provided, the form data is URL encoded and sent as \nthe body of the request. If no Content-type header is provided, a default Content-type header with value application/x-www-form-urlencoded will be set. If both form and file members are provided, both form and file data are included \nas part of the request body. A default Content-type header with value multipart/form-data will be set if no Content-type header is provided. If data , form , and file are all provided, only data is sent, and the form and file inputs are ignored. Combination Behavior Table Passed Arguments Request Body Default Header Behavior data data None The data is sent as the body of the request. file file multipart/form-data The file is sent as the body of the request with the default header. form Form data URL encoded application/x-www-form-urlencoded The form data is sent as the body of the request with the default header. data + file data (file ignored) None The file member is ignored, and the data is sent as the body of the request. data + form data (form ignored) None The form member is ignored, and the data is sent as the body of the request. file + form both file and form multipart/form-data Both form and file are sent as part of the request. data + file + form data (form and file ignored) None Both form and file members are ignored, and only the data is sent as the body of the request. Note: If custom headers are provided in the headers parameter, they will be used. Otherwise, default headers will be applied as mentioned in the table. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer value representing the status of the function call. Contents Source Code set_body Source Code function set_body ( curl_ptr , request ) result ( status ) !!> The function sets the request `body`. !!____ !!> This function determines and set the type of data to include in the `request body` !!> based on the inputs provided to the `request()` procedure. !!> The function handles different combinations of `data`, `file`, and `form` members !!> to decide the content and the default header for the request body. !!> - If `data` member is provided, it takes the highest priority and is sent as the !!> body of the request. Any other provided `file` or `form` members will be ignored, !!> and only the `data` member will be included in the request body. !!> - If only the `file` member is provided, the `file` is sent as the body of the request. !!> If no `Content-type` header is provided, a default `Content-type` header with value !!> `multipart/form-data` will be set. !!> - If only the `form` member is provided, the `form` data is URL encoded and sent as !!> the body of the request. If no `Content-type` header is provided, a default `Content-type` !!> header with value `application/x-www-form-urlencoded` will be set. !!> - If both `form` and `file` members are provided, both `form` and `file` data are included !!> as part of the request body. A default `Content-type` header with value `multipart/form-data` !!> will be set if no `Content-type` header is provided. !!> - If `data`, `form`, and `file` are all provided, only `data` is sent, and the `form` and `file` !!> inputs are ignored. !!> ### **Combination Behavior Table** !!> | Passed Arguments | Request Body | Default Header | Behavior | !! |--------------------|---------------------------------|-------------------------------|---------------------------------------------------------| !! | data | data | None | The `data` is sent as the body of the request. | !! | file | file | multipart/form-data | The `file` is sent as the body of the request with the default header. | !! | form | Form data URL encoded | application/x-www-form-urlencoded | The `form` data is sent as the body of the request with the default header. | !! | data + file | data (file ignored) | None | The `file` member is ignored, and the `data` is sent as the body of the request. | !! | data + form | data (form ignored) | None | The `form` member is ignored, and the `data` is sent as the body of the request. | !! | file + form | both file and form | multipart/form-data | Both `form` and `file` are sent as part of the request. | !! | data + file + form | data (form and file ignored) | None | Both `form` and `file` members are ignored, and only the `data` is sent as the body of the request. | !!> Note: If custom headers are provided in the `headers` parameter, they will be used. Otherwise, default headers will be applied as mentioned in the table. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer value representing the status of the function call. integer :: i type ( c_ptr ) :: mime_ptr , part_ptr ! if only data is passed if ( allocated ( request % data )) then status = set_postfields ( curl_ptr , request % data ) ! if file is passsed else if ( allocated ( request % file )) then mime_ptr = curl_mime_init ( curl_ptr ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_filedata ( part_ptr , request % file % value ) status = curl_mime_name ( part_ptr , request % file % name ) ! if both file and form are passed if ( allocated ( request % form )) then do i = 1 , size ( request % form ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_data ( part_ptr , request % form ( i )% value , CURL_ZERO_TERMINATED ) status = curl_mime_name ( part_ptr , request % form ( i )% name ) end do end if status = curl_easy_setopt ( curl_ptr , CURLOPT_MIMEPOST , mime_ptr ) ! setting the Content-Type header to multipart/form-data, used for sending binary data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'multipart/form-data' ) end if ! if only form is passed else if ( allocated ( request % form )) then request % form_encoded_str = prepare_form_encoded_str ( curl_ptr , request ) status = set_postfields ( curl_ptr , request % form_encoded_str ) ! setting the Content-Type header to application/x-www-form-urlencoded, used for sending form data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'application/x-www-form-urlencoded' ) end if else ! No curl function was called so set status to zero. status = 0 end if end function set_body","tags":"","loc":"proc/set_body.html"},{"title":"set_postfields – HTTP","text":"private function set_postfields(curl_ptr, data) result(status) Set the data to be sent in the HTTP POST request body. Use as helper function by set_body procedure to set request body Arguments Type Intent Optional Attributes Name type(c_ptr), intent(inout) :: curl_ptr Pointer to the CURL handle. character(len=*), intent(in), target :: data The data to be sent in the request body. Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). Contents Source Code set_postfields Source Code function set_postfields ( curl_ptr , data ) result ( status ) !!> Set the data to be sent in the HTTP POST request body. !!____ !!> Use as helper function by `set_body` procedure to set request body type ( c_ptr ), intent ( inout ) :: curl_ptr !! Pointer to the CURL handle. character ( * ), intent ( in ), target :: data !! The data to be sent in the request body. integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDS , c_loc ( data )) status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDSIZE_LARGE , len ( data , kind = int64 )) end function set_postfields","tags":"","loc":"proc/set_postfields.html"},{"title":"set_auth – HTTP","text":"private function set_auth(curl_ptr, request) result(status) Set the user name and password for Authentication. It sends the user name and password over the network in plain text, easily captured by others. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the CURL handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). Contents Source Code set_auth Source Code function set_auth ( curl_ptr , request ) result ( status ) !!> Set the user name and password for Authentication. !!_____ !!> It sends the user name and password over the network in plain text, easily captured by others. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the CURL handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). if ( allocated ( request % auth )) then status = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) status = curl_easy_setopt ( curl_ptr , CURLOPT_USERNAME , request % auth % name ) status = curl_easy_setopt ( curl_ptr , CURLOPT_PASSWORD , request % auth % value ) else ! No curl function was called so set status to zero. status = 0 end if end function set_auth","tags":"","loc":"proc/set_auth.html"},{"title":"client_response_callback – HTTP","text":"private function client_response_callback(ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP responses. \nIt is called for each chunk of data received from the server and appends the data to a response_type object. It is called for each chunk of data received from the server and appends the data to a response_type object passed(i.e client_data ). The function takes four input arguments: ptr , size , nmemb , and client_data . ptr is a pointer to the received data buffer, size specifies the size of each \ndata element, nmemb specifies the number of data elements received, and client_data is a pointer to a response_type object. The function uses c_f_pointer to convert the C pointer to a Fortran pointer and \nappends the received data to the content field of the response_type object. The function returns an integer\nvalue representing the number of bytes received. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each data element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of data elements received. type(c_ptr), intent(in), value :: client_data Points to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. Contents Source Code client_response_callback Source Code function client_response_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the fortran-curl package to handle HTTP responses. !!> It is called for each `chunk` of data received from the server and appends the data to a !!> `response_type` object. !!>_____ !!> It is called for each `chunk` of data received from the server and appends the data to a `response_type` !!> object passed(i.e `client_data`). The function takes four input arguments: `ptr`, `size`, `nmemb`, !!> and `client_data`. `ptr` is a pointer to the received data buffer, `size` specifies the size of each !!> data element, `nmemb` specifies the number of data elements received, and `client_data` is a pointer to !!> a `response_type` object. The function uses `c_f_pointer` to convert the C pointer to a Fortran pointer and !!> appends the received data to the `content` field of the `response_type` object. The function returns an integer !!> value representing the **number of bytes received.** type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each data element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of data elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Points to a response_type object. integer ( kind = c_size_t ) :: client_response_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf client_response_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) if (. not . allocated ( response % content )) response % content = '' ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return response % content = response % content // buf deallocate ( buf ) response % content_length = response % content_length + nmemb ! Return number of received bytes. client_response_callback = nmemb end function client_response_callback","tags":"","loc":"proc/client_response_callback.html"},{"title":"client_header_callback – HTTP","text":"private function client_header_callback(ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP headers. It is called for each header received from the server and stores the header in an header member \nof response_type object. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. that points to the received header buffer. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each header element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of header elements received. type(c_ptr), intent(in), value :: client_data Pointer to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. Contents Source Code client_header_callback Source Code function client_header_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the `fortran-curl` package to handle HTTP headers. !!>_____ !!> It is called for each header received from the server and stores the header in an `header` member !!> of `response_type` object. type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. that points to the received header buffer. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each header element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of header elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Pointer to a `response_type` object. integer ( kind = c_size_t ) :: client_header_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf , h_name , h_value integer :: i client_header_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return ! Parsing Header, and storing in array of pair_type object i = index ( buf , ':' ) if ( i /= 0 . and . len ( buf ) > 2 ) then h_name = trim ( buf (: i - 1 )) h_value = buf ( i + 2 : ) h_value = h_value ( : len ( h_value ) - 2 ) if ( len ( h_value ) > 0 . and . len ( h_name ) > 0 ) then call append_pair ( response % header , h_name , h_value ) ! response%header = [response%header, pair_type(h_name, h_value)] end if end if deallocate ( buf ) ! Return number of received bytes. client_header_callback = nmemb end function client_header_callback","tags":"","loc":"proc/client_header_callback.html"},{"title":"prepare_request_header_ptr – HTTP","text":"private subroutine prepare_request_header_ptr(header_list_ptr, req_headers) This subroutine prepares headers in required format(Linked list) for an HTTP request. This subroutine prepares a linked list of headers for an HTTP request using the fortran-curl package. \nThe function takes an array of pair_type objects(i.e. req_headers ) that contain the key-value pairs of the headers to include in the request.\nIt iterates over the array and constructs a string for each header in the format key:value .\nThe subroutine then appends each string to the linked list using the curl_slist_append function.\nThe resulting linked list is returned via the header_list_ptr argument. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: header_list_ptr A Pointer that is allocated and points to a linked list of headers. type( pair_type ), intent(in), allocatable :: req_headers (:) The headers to be included in the request. Contents Source Code prepare_request_header_ptr Source Code subroutine prepare_request_header_ptr ( header_list_ptr , req_headers ) !!> This subroutine prepares `headers` in required format(Linked list) for an HTTP request. !!____ !!> This subroutine prepares a **linked list** of `headers` for an HTTP request using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package. !!> The function takes an array of `pair_type` objects(i.e. `req_headers`) that contain the !!> **key-value** pairs of the headers to include in the request. !!> It iterates over the array and constructs a string for each header in the format **`key:value`**. !!> The subroutine then appends each string to the linked list using the `curl_slist_append` function. !!> The resulting linked list is returned via the `header_list_ptr` argument. type ( c_ptr ), intent ( out ) :: header_list_ptr !! A `Pointer` that is allocated and points to a linked list of headers. type ( pair_type ), allocatable , intent ( in ) :: req_headers (:) !! The `headers` to be included in the request. character (:), allocatable :: h_name , h_val , final_header_string integer :: i do i = 1 , size ( req_headers ) h_name = req_headers ( i )% name h_val = req_headers ( i )% value final_header_string = h_name // ':' // h_val header_list_ptr = curl_slist_append ( header_list_ptr , final_header_string ) end do end subroutine prepare_request_header_ptr","tags":"","loc":"proc/prepare_request_header_ptr.html"},{"title":"client_type – HTTP","text":"private interface client_type Interface for new_client function. Contents Module Procedures new_client Module Procedures private function new_client (request) result(client) This is the constructor for the client_type derived type. Read more… Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object.","tags":"","loc":"interface/client_type.html"},{"title":"request – HTTP","text":"public interface request Interface for new_request function. Contents Module Procedures new_request Module Procedures private function new_request (url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Read more… Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response .","tags":"","loc":"interface/request.html"},{"title":"get_pair_value – HTTP","text":"public pure function get_pair_value(pair_arr, name) result(val) The function retrieves the value associated with a specified name from the passed array of pair_type objects (i.e., pair_arr). \nThe search for the name is case-insensitive . If the name is \nnot found, the function returns an unallocated string . In the case \nof duplicate name entries in the pair_arr , the function returns the value of the first occurrence of the name . Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value character(len=:), allocatable Stores the value of the corresponding pair_type object whose name attribute is equal to the given name . Contents Source Code get_pair_value Source Code pure function get_pair_value ( pair_arr , name ) result ( val ) !!> The function retrieves the `value` associated with a specified !!> `name` from the passed array of `pair_type` objects (i.e., pair_arr). !!> The search for the `name` is **case-insensitive**. If the `name` is !!> not found, the function returns an **unallocated string**. In the case !!> of duplicate `name` entries in the `pair_arr`, the function returns the !!> `value` of the **first occurrence** of the `name`. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. character (:), allocatable :: val !! Stores the `value` of the corresponding `pair_type` object whose `name` !! attribute is equal to the given `name`. integer :: n do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then val = pair_arr ( n )% value return end if end do end function get_pair_value","tags":"","loc":"proc/get_pair_value.html"},{"title":"pair_has_name – HTTP","text":"public pure function pair_has_name(pair_arr, name) Return .true. if there exists a pair_type object inside pair_arr with \na name attribute equal to the provided name ; otherwise, return .false. . \nHTTP pairs are case-insensitive , implying that values are converted to \nlowercase before the comparison is performed. Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value logical Contents Source Code pair_has_name Source Code pure logical function pair_has_name ( pair_arr , name ) !!> Return `.true.` if there exists a `pair_type` object inside `pair_arr` with !!> a `name` attribute equal to the provided `name`; otherwise, return `.false.`. !!> HTTP pairs are **case-insensitive**, implying that values are **converted to !!> lowercase** before the comparison is performed. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. integer :: n pair_has_name = . false . do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then pair_has_name = . true . return end if end do end function pair_has_name","tags":"","loc":"proc/pair_has_name.html"},{"title":"append_pair – HTTP","text":"public subroutine append_pair(pair, name, value) Appends a new pair_type instance with the provided name and value into the given pair_type array (i.e pair). Arguments Type Intent Optional Attributes Name type( pair_type ), intent(inout), allocatable :: pair (:) An array of pair_type objects, to which a new instance of pair_type needs to be added. character(len=*), intent(in) :: name The name attribute of the pair_type to be added. character(len=*), intent(in) :: value The value attribute of the pair_type to be added. Contents Source Code append_pair Source Code subroutine append_pair ( pair , name , value ) !!> Appends a new `pair_type` instance with the provided `name` !!> and `value` into the given `pair_type array`(i.e pair). type ( pair_type ), allocatable , intent ( inout ) :: pair (:) !! An array of `pair_type` objects, to which a new instance of `pair_type` needs to be added. character ( * ), intent ( in ) :: name !! The `name` attribute of the `pair_type` to be added. character ( * ), intent ( in ) :: value !! The `value` attribute of the `pair_type` to be added. type ( pair_type ), allocatable :: temp (:) integer :: n if ( allocated ( pair )) then n = size ( pair ) allocate ( temp ( n + 1 )) temp ( 1 : n ) = pair temp ( n + 1 ) = pair_type ( name , value ) call move_alloc ( temp , pair ) else allocate ( pair ( 1 )) pair ( 1 ) = pair_type ( name , value ) end if end subroutine append_pair","tags":"","loc":"proc/append_pair.html"},{"title":"http – HTTP","text":"This Module contains all High-level API for the HTTP package. \nWhen the http module is imported into the project, all these \nhigh-level functionalities become available for use. Uses http_client http_request http_pair http_response Contents None","tags":"","loc":"module/http.html"},{"title":"http_version – HTTP","text":"This module store information regarding version number of package Contents Variables VERSION_MAJOR VERSION_MINOR VERSION_STRING Variables Type Visibility Attributes Name Initial integer, public, parameter :: VERSION_MAJOR = 0 major version number integer, public, parameter :: VERSION_MINOR = 1 minor version number character(len=*), public, parameter :: VERSION_STRING = achar(VERSION_MAJOR+48)//'.'//achar(VERSION_MINOR+48) string representation of version number","tags":"","loc":"module/http_version.html"},{"title":"http_response – HTTP","text":"This module defines the response_type derived type, which \nrepresents an HTTP response from a web server. Uses stdlib_string_type iso_fortran_env http_pair Contents Derived Types response_type Functions header_value Derived Types type, public :: response_type Representing an HTTP response . Read more… Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: content The content of the response. character(len=:), public, allocatable :: method The HTTP method of the request. character(len=:), public, allocatable :: err_msg The Error message if the response was not successful. integer, public :: status_code = 0 The HTTP status code of the response integer(kind=int64), public :: content_length = 0 length of the response content. logical, public :: ok = .true. true if the response was successful else false. type( pair_type ), public, allocatable :: header (:) An Array of response headers. Type-Bound Procedures procedure\n , public\n, :: header_value Function Functions private pure function header_value (this, name) result(val) This function is used to retrieve the value of a response header. \nIt takes the response header name as input and returns the corresponding header value . Read more… Arguments Type Intent Optional Attributes Name class( response_type ), intent(in) :: this An object representing the HTTP response. character(len=*), intent(in) :: name This refers to the name of the header for which we want to retrieve the value. Return Value character(len=:), allocatable This denotes the value of the specified header name.","tags":"","loc":"module/http_response.html"},{"title":"http_request – HTTP","text":"This module defines the request_type derived type, which \nrepresents an HTTP request . Uses stdlib_string_type iso_fortran_env http_pair Contents Variables HTTP_GET HTTP_HEAD HTTP_POST HTTP_PUT HTTP_DELETE HTTP_PATCH Derived Types request_type Variables Type Visibility Attributes Name Initial integer, public, parameter :: HTTP_GET = 1 integer, public, parameter :: HTTP_HEAD = 2 integer, public, parameter :: HTTP_POST = 3 integer, public, parameter :: HTTP_PUT = 4 integer, public, parameter :: HTTP_DELETE = 5 integer, public, parameter :: HTTP_PATCH = 6 Derived Types type, public :: request_type Representing an HTTP request . Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: data The data to be send with request character(len=:), public, allocatable :: form_encoded_str The URL-encoded form data. integer, public :: method The HTTP method of the request. type( pair_type ), public, allocatable :: header (:) An Array of request headers. type( pair_type ), public, allocatable :: form (:) An array of fields in an HTTP form. type( pair_type ), public, allocatable :: file Used to store information about files to be sent in HTTP requests. integer(kind=int64), public :: timeout Timeout value for the request in seconds . type( pair_type ), public, allocatable :: auth Stores the username and password for Authentication","tags":"","loc":"module/http_request.html"},{"title":"http_client – HTTP","text":"This module defines the client_type derived type, which handles the \nprocess of making HTTP requests . The actual HTTP requests are executed \nusing the Fortran-curl package as the underlying mechanism. Uses iso_fortran_env http_response curl stdlib_optval http_request iso_c_binding http_pair http_version Contents Interfaces client_type request Derived Types client_type Functions new_request new_client client_get_response prepare_form_encoded_str set_method set_timeout set_body set_postfields set_auth client_response_callback client_header_callback Subroutines prepare_request_header_ptr Interfaces private interface client_type Interface for new_client function. private function new_client (request) result(client) This is the constructor for the client_type derived type. Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. public interface request Interface for new_request function. private function new_request (url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Note : If the header argument is not provided, default user-agent header is set to http-client/0.1 . Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response . Derived Types type, private :: client_type A derived type, responsible for making actual HTTP request using\nfortran-curl at backend. Read more… Components Type Visibility Attributes Name Initial type( request_type ), public :: request Constructor Interface for new_client function. Read more… private\n\n \n function new_client (request) This is the constructor for the client_type derived type. Read more… Type-Bound Procedures procedure\n , public\n, :: client_get_response Function Functions private function new_request (url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Read more… Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response . private function new_client (request) result(client) This is the constructor for the client_type derived type. Read more… Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. private function client_get_response (this) result(response) This function sends an HTTP request to a server using the fortran-curl package \nand stores the server's response in a response_type object. Read more… Arguments Type Intent Optional Attributes Name class( client_type ), intent(inout) :: this Contains the HTTP request to send. Return Value type( response_type ), target Contains the server's response . private function prepare_form_encoded_str (curl_ptr, request) result(form_encoded_str) This subroutine converts the request%form into a URL-encoded name-value \nstring and returns it. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. type( request_type ), intent(inout) :: request The HTTP request to send, which includes the form data to be encoded. Return Value character(len=:), allocatable Stores the URL Encoded string . private function set_method (curl_ptr, method, response) result(status) This function sets the HTTP method for the request. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. integer, intent(in) :: method Specifies the HTTP method to use. type( response_type ), intent(out) :: response The HTTP response from the server. Return Value integer The status of setting HTTP method. private function set_timeout (curl_ptr, timeout) result(status) This function sets the timeout value (in seconds) . Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. integer(kind=int64), intent(in) :: timeout Timeout seconds for request. Return Value integer Status code indicating whether the operation was successful. private function set_body (curl_ptr, request) result(status) The function sets the request body . Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer value representing the status of the function call. private function set_postfields (curl_ptr, data) result(status) Set the data to be sent in the HTTP POST request body. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(inout) :: curl_ptr Pointer to the CURL handle. character(len=*), intent(in), target :: data The data to be sent in the request body. Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). private function set_auth (curl_ptr, request) result(status) Set the user name and password for Authentication. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the CURL handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). private function client_response_callback (ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP responses. \nIt is called for each chunk of data received from the server and appends the data to a response_type object. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each data element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of data elements received. type(c_ptr), intent(in), value :: client_data Points to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. private function client_header_callback (ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP headers. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. that points to the received header buffer. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each header element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of header elements received. type(c_ptr), intent(in), value :: client_data Pointer to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. Subroutines private subroutine prepare_request_header_ptr (header_list_ptr, req_headers) This subroutine prepares headers in required format(Linked list) for an HTTP request. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: header_list_ptr A Pointer that is allocated and points to a linked list of headers. type( pair_type ), intent(in), allocatable :: req_headers (:) The headers to be included in the request.","tags":"","loc":"module/http_client.html"},{"title":"http_pair – HTTP","text":"This module contains the pair_type derived type, designed to \nstore various details like headers , file information, form-data , \nand authentication details. Uses stdlib_ascii Contents Derived Types pair_type Functions get_pair_value pair_has_name Subroutines append_pair Derived Types type, public :: pair_type A derived type use to store a name-value pair . Read more… Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: name Name (key) character(len=:), public, allocatable :: value Value Functions public pure function get_pair_value (pair_arr, name) result(val) The function retrieves the value associated with a specified name from the passed array of pair_type objects (i.e., pair_arr). \nThe search for the name is case-insensitive . If the name is \nnot found, the function returns an unallocated string . In the case \nof duplicate name entries in the pair_arr , the function returns the value of the first occurrence of the name . Read more… Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value character(len=:), allocatable Stores the value of the corresponding pair_type object whose name attribute is equal to the given name . public pure function pair_has_name (pair_arr, name) Return .true. if there exists a pair_type object inside pair_arr with \na name attribute equal to the provided name ; otherwise, return .false. . \nHTTP pairs are case-insensitive , implying that values are converted to \nlowercase before the comparison is performed. Read more… Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value logical Subroutines public subroutine append_pair (pair, name, value) Appends a new pair_type instance with the provided name and value into the given pair_type array (i.e pair). Read more… Arguments Type Intent Optional Attributes Name type( pair_type ), intent(inout), allocatable :: pair (:) An array of pair_type objects, to which a new instance of pair_type needs to be added. character(len=*), intent(in) :: name The name attribute of the pair_type to be added. character(len=*), intent(in) :: value The value attribute of the pair_type to be added.","tags":"","loc":"module/http_pair.html"},{"title":"http.f90 – HTTP","text":"This file provides the High-Level API for the HTTP package. \nWhen the http module is imported into the project, all these \nhigh-level functionalities become available for use. Contents Modules http Source Code http.f90 Source Code !!> This file provides the **High-Level API** for the **`HTTP`** package. !!> When the `http` module is imported into the project, all these !!> high-level functionalities become available for use. module http !!> This Module contains all **High-level API** for the **`HTTP`** package. !!> When the `http` module is imported into the project, all these !!> high-level functionalities become available for use. use http_request , only : & HTTP_DELETE , HTTP_GET , HTTP_HEAD , HTTP_PATCH , HTTP_POST , HTTP_PUT use http_response , only : response_type use http_client , only : request use http_pair , only : pair_type end module http","tags":"","loc":"sourcefile/http.f90.html"},{"title":"http_version.f90 – HTTP","text":"This file provides details about the version number of the package. Contents Modules http_version Source Code http_version.f90 Source Code !!> This file provides details about the **`version number`** of the package. module http_version !!> This module store information regarding **`version`** !!> number of package integer , parameter , public :: VERSION_MAJOR = 0 !! major version number integer , parameter , public :: VERSION_MINOR = 1 !! minor version number character ( len =* ), parameter , public :: VERSION_STRING = achar ( VERSION_MAJOR + 48 ) // '.' // achar ( VERSION_MINOR + 48 ) !! string representation of version number end module http_version","tags":"","loc":"sourcefile/http_version.f90.html"},{"title":"http_response.f90 – HTTP","text":"This file defines the response_type derived type, which \nrepresents an HTTP response from a web server. Contents Modules http_response Source Code http_response.f90 Source Code !!> This file defines the **`response_type`** derived type, which !!> represents an **HTTP response** from a web server. module http_response !!> This module defines the **`response_type`** derived type, which !!> represents an **HTTP response** from a web server. use , intrinsic :: iso_fortran_env , only : int64 use http_pair , only : pair_type , get_pair_value use stdlib_string_type , only : string_type , to_lower , operator ( == ), char implicit none private public :: response_type ! Response Type type :: response_type !!> Representing an **HTTP `response`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: content !! The content of the response. character ( len = :), allocatable :: method !! The HTTP method of the request. character ( len = :), allocatable :: err_msg !! The Error message if the response was not successful. integer :: status_code = 0 !! The HTTP status code of the response integer ( kind = int64 ) :: content_length = 0 !! length of the response content. logical :: ok = . true . !! true if the response was successful else false. type ( pair_type ), allocatable :: header (:) !! An Array of response headers. contains procedure :: header_value end type response_type contains pure function header_value ( this , name ) result ( val ) !!> This function is used to retrieve the `value` of a response header. !!> It takes the response header `name` as input and returns the corresponding !!> **header value**. class ( response_type ), intent ( in ) :: this !! An object representing the HTTP response. character ( * ), intent ( in ) :: name !! This refers to the name of the header for which we want to retrieve the value. character (:), allocatable :: val !! This denotes the value of the specified header name. val = get_pair_value ( this % header , name ) end function header_value end module http_response","tags":"","loc":"sourcefile/http_response.f90.html"},{"title":"http_request.f90 – HTTP","text":"This file defines the request_type derived type, which \nrepresents an HTTP request . Contents Modules http_request Source Code http_request.f90 Source Code !!> This file defines the **`request_type`** derived type, which !!> represents an **HTTP request**. module http_request !!> This module defines the **`request_type`** derived type, which !!> represents an **HTTP request**. use iso_fortran_env , only : int64 use http_pair , only : pair_type use stdlib_string_type , only : string_type , to_lower , operator ( == ), char implicit none private public :: HTTP_DELETE , HTTP_GET , HTTP_HEAD , HTTP_PATCH , HTTP_POST , HTTP_PUT public :: request_type ! HTTP methods: integer , parameter :: HTTP_GET = 1 integer , parameter :: HTTP_HEAD = 2 integer , parameter :: HTTP_POST = 3 integer , parameter :: HTTP_PUT = 4 integer , parameter :: HTTP_DELETE = 5 integer , parameter :: HTTP_PATCH = 6 ! Request Type type :: request_type !! Representing an **HTTP `request`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: data !! The data to be send with request character ( len = :), allocatable :: form_encoded_str !! The URL-encoded form data. integer :: method !! The HTTP method of the request. type ( pair_type ), allocatable :: header (:) !! An Array of request headers. type ( pair_type ), allocatable :: form (:) !! An array of fields in an HTTP form. type ( pair_type ), allocatable :: file !! Used to store information about files to be sent in HTTP requests. integer ( kind = int64 ) :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), allocatable :: auth !! Stores the username and password for Authentication end type request_type end module http_request","tags":"","loc":"sourcefile/http_request.f90.html"},{"title":"http_client.f90 – HTTP","text":"This file defines the client_type derived type, which handles the \nprocess of making HTTP requests . The actual HTTP requests are executed \nusing the Fortran-curl package as the underlying mechanism. Contents Modules http_client Source Code http_client.f90 Source Code !!> This file defines the **`client_type`** derived type, which handles the !!> process of making **HTTP requests**. The actual HTTP requests are executed !!> using the [Fortran-curl](https://github.com/interkosmos/fortran-curl) !!> package as the underlying mechanism. module http_client !!> This module defines the **`client_type`** derived type, which handles the !!> process of making **HTTP requests**. The actual HTTP requests are executed !!> using the [Fortran-curl](https://github.com/interkosmos/fortran-curl) !!> package as the underlying mechanism. use iso_fortran_env , only : int64 use iso_c_binding , only : c_associated , c_f_pointer , c_funloc , c_loc , & c_null_ptr , c_ptr , c_size_t , c_null_char use curl , only : c_f_str_ptr , curl_easy_cleanup , curl_easy_getinfo , & curl_easy_init , curl_easy_perform , curl_easy_setopt , & curl_easy_strerror , curl_slist_append , CURLE_OK , & CURLINFO_RESPONSE_CODE , CURLOPT_CUSTOMREQUEST , CURLOPT_HEADERDATA , & CURLOPT_HEADERFUNCTION , CURLOPT_HTTPHEADER , CURLOPT_URL , & CURLOPT_WRITEDATA , CURLOPT_WRITEFUNCTION , & CURLOPT_POSTFIELDS , CURLOPT_POSTFIELDSIZE_LARGE , curl_easy_escape , & curl_mime_init , curl_mime_addpart , curl_mime_filedata , curl_mime_name , & CURLOPT_MIMEPOST , curl_mime_data , CURL_ZERO_TERMINATED , & CURLOPT_TIMEOUT , CURLOPT_CONNECTTIMEOUT , & CURLOPT_HTTPAUTH , CURLAUTH_BASIC , CURLOPT_USERNAME , CURLOPT_PASSWORD use stdlib_optval , only : optval use http_request , only : request_type use http_response , only : response_type use http_pair , only : append_pair , pair_has_name , pair_type use http_version , only : VERSION_STRING implicit none private public :: request ! http_client Type type :: client_type !!> A derived type, responsible for making **actual HTTP `request`** using !!> fortran-curl at backend. type ( request_type ) :: request contains procedure :: client_get_response end type client_type interface client_type !!> Interface for `new_client` function. module procedure new_client end interface client_type interface request !!> Interface for `new_request` function. module procedure new_request end interface request contains function new_request ( url , method , header , data , form , file , timeout , auth ) result ( response ) !!> This function create a `request_type` object and populates it. !!> The function returns the `response_type` object containing the !!> **server's response**. !!____ !!> #### Note : !!> If the `header` argument is not provided, **default `user-agent` !!> header is set to `http-client/0.1`**. integer , intent ( in ), optional :: method !! Specifies the HTTP `method` to use for the request. !! The **default value is 1**, which corresponds to the **`HTTP_GET`** method. character ( len =* ), intent ( in ) :: url !! Specifies the **`URL`** of the server. character ( len =* ), intent ( in ), optional :: data !! Specifies the **`data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: header (:) !! Specifies the **request `headers`** that need to be sent to the server. type ( pair_type ), intent ( in ), optional :: form (:) !! Specifies the **`form data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: file !! Specifies the **`file`** that needs to be sent to the server. integer , intent ( in ), optional :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), intent ( in ), optional :: auth !! stores the `username` and `password` for **`authentication`** purposes. type ( response_type ) :: response !! Stores the server's **`response`**. type ( request_type ) :: request type ( client_type ) :: client integer :: i ! setting request url request % url = url ! Set default HTTP method. request % method = optval ( method , 1 ) ! Set request header if ( present ( header )) then request % header = header ! Set default request headers. if (. not . pair_has_name ( header , 'user-agent' )) then call append_pair ( request % header , 'user-agent' , 'http-client/' // VERSION_STRING ) end if else ! Set default request headers. request % header = [ pair_type ( 'user-agent' , 'http-client/' // VERSION_STRING )] end if ! setting the request data to be send if ( present ( data )) then request % data = data end if ! setting request form if ( present ( form )) then request % form = form end if ! setting request file if ( present ( file )) then request % file = file end if ! Set request timeout. request % timeout = optval ( timeout , - 1 ) ! setting username and password for Authentication if ( present ( auth )) then request % auth = auth end if ! Populates the response client = client_type ( request = request ) response = client % client_get_response () end function new_request function new_client ( request ) result ( client ) !!> This is the constructor for the `client_type` derived type. type ( request_type ), intent ( in ) :: request !! Specifies the **HTTP `request`** to send. type ( client_type ) :: client !! A `client_type` object containing the `request` field set to the input `request` object. client % request = request end function new_client function client_get_response ( this ) result ( response ) !!> This function sends an HTTP `request` to a server using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package !!> and stores the server's response in a `response_type` !!> object. class ( client_type ), intent ( inout ) :: this !! Contains the HTTP `request` to send. type ( response_type ), target :: response !! Contains the **server's response**. type ( c_ptr ) :: curl_ptr , header_list_ptr integer :: rc , i curl_ptr = c_null_ptr header_list_ptr = c_null_ptr response % url = this % request % url curl_ptr = curl_easy_init () if (. not . c_associated ( curl_ptr )) then response % ok = . false . response % err_msg = \"The initialization of a new easy handle using the 'curl_easy_init()'& & function failed. This can occur due to insufficient memory available in the system. & & Additionally, if libcurl is not installed or configured properly on the system\" return end if ! setting request URL rc = curl_easy_setopt ( curl_ptr , CURLOPT_URL , this % request % url ) ! setting request method rc = set_method ( curl_ptr , this % request % method , response ) ! setting request timeout rc = set_timeout ( curl_ptr , this % request % timeout ) ! setting request body rc = set_body ( curl_ptr , this % request ) ! setting request authentication rc = set_auth ( curl_ptr , this % request ) ! prepare headers for curl call prepare_request_header_ptr ( header_list_ptr , this % request % header ) ! setting request header rc = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPHEADER , header_list_ptr ); ! setting callback for writing received data rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEFUNCTION , c_funloc ( client_response_callback )) ! setting response content pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEDATA , c_loc ( response )) ! setting callback for writing received headers rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERFUNCTION , c_funloc ( client_header_callback )) ! setting response header pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERDATA , c_loc ( response )) ! Send request. rc = curl_easy_perform ( curl_ptr ) if ( rc /= CURLE_OK ) then response % ok = . false . response % err_msg = curl_easy_strerror ( rc ) end if ! setting response status_code rc = curl_easy_getinfo ( curl_ptr , CURLINFO_RESPONSE_CODE , response % status_code ) call curl_easy_cleanup ( curl_ptr ) end function client_get_response function prepare_form_encoded_str ( curl_ptr , request ) result ( form_encoded_str ) !!> This subroutine converts the `request%form` into a **URL-encoded name-value !!> string** and returns it. ! This subroutine takes a request object containing a list of name-value pairs ! representing the form data. It iterates over the list and URL-encodes each ! name and value using the curl_easy_escape function, which replaces special ! characters with their corresponding escape sequences. ! The encoded name-value pairs are concatenated into a single string, separated ! by '&' characters. The resulting string is returned type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. type ( request_type ), intent ( inout ) :: request !! The HTTP `request` to send, which includes the `form` data to be encoded. character (:), allocatable :: form_encoded_str !! Stores the **URL Encoded string**. integer :: i if ( allocated ( request % form )) then do i = 1 , size ( request % form ) if (. not . allocated ( form_encoded_str )) then form_encoded_str = curl_easy_escape ( curl_ptr , request % form ( i )% name , & len ( request % form ( i )% name )) // '=' // curl_easy_escape ( curl_ptr , & request % form ( i )% value , len ( request % form ( i )% value )) else form_encoded_str = form_encoded_str // '&' // & curl_easy_escape ( curl_ptr , request % form ( i )% name , len ( request % form ( i )% name ))& // '=' // curl_easy_escape ( curl_ptr , request % form ( i )% value , len ( request % form ( i )% value )) end if end do end if end function prepare_form_encoded_str subroutine prepare_request_header_ptr ( header_list_ptr , req_headers ) !!> This subroutine prepares `headers` in required format(Linked list) for an HTTP request. !!____ !!> This subroutine prepares a **linked list** of `headers` for an HTTP request using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package. !!> The function takes an array of `pair_type` objects(i.e. `req_headers`) that contain the !!> **key-value** pairs of the headers to include in the request. !!> It iterates over the array and constructs a string for each header in the format **`key:value`**. !!> The subroutine then appends each string to the linked list using the `curl_slist_append` function. !!> The resulting linked list is returned via the `header_list_ptr` argument. type ( c_ptr ), intent ( out ) :: header_list_ptr !! A `Pointer` that is allocated and points to a linked list of headers. type ( pair_type ), allocatable , intent ( in ) :: req_headers (:) !! The `headers` to be included in the request. character (:), allocatable :: h_name , h_val , final_header_string integer :: i do i = 1 , size ( req_headers ) h_name = req_headers ( i )% name h_val = req_headers ( i )% value final_header_string = h_name // ':' // h_val header_list_ptr = curl_slist_append ( header_list_ptr , final_header_string ) end do end subroutine prepare_request_header_ptr function set_method ( curl_ptr , method , response ) result ( status ) !!> This function sets the **HTTP `method`** for the request. !!____ !!#### **The `method` argument can take one of the following values:** !!> `HTTP_GET`, `HTTP_HEAD`, `HTTP_POST`, `HTTP_PUT`, `HTTP_DELETE`, !!> `HTTP_PATCH`. If any other value is provided, an **error will be thrown**. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. integer , intent ( in ) :: method !! Specifies the HTTP `method` to use. type ( response_type ), intent ( out ) :: response !! The HTTP `response` from the server. integer :: status !! The `status` of setting HTTP method. select case ( method ) case ( 1 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'GET' ) response % method = 'GET' case ( 2 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'HEAD' ) response % method = 'HEAD' case ( 3 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'POST' ) response % method = 'POST' case ( 4 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PUT' ) response % method = 'PUT' case ( 5 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'DELETE' ) response % method = 'DELETE' case ( 6 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PATCH' ) response % method = 'PATCH' case default error stop 'Method argument can be either HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_PATCH' end select end function set_method function set_timeout ( curl_ptr , timeout ) result ( status ) !!> This function sets the `timeout` value **(in seconds)**. !!> !!> If the `timeout` value is **less than zero**, it is ignored and a success status is returned. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. integer ( kind = int64 ), intent ( in ) :: timeout !! `Timeout` seconds for request. integer :: status !! `Status code` indicating whether the operation was successful. if ( timeout < 0 ) then status = 0 else ! setting the maximum time allowed for the connection to established.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_CONNECTTIMEOUT , timeout ) ! setting maximum time allowed for transfer operation.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_TIMEOUT , timeout ) end if end function set_timeout ! This function determines the type of data to include in the `request body` ! based on the inputs provided. ! If `data` member is provided, it is sent as the body of the ! request. If along with `data` member `file` or `form` or both `file` and `form` members ! are provided then both `form` and `file` member will be ignored and only `data` member will be ! sent in request body. `data` argument takes the highest priority. ! If only `file` member is provided then `file` is sent as the body of the request. and ! a default `Content-type` header with value `multipart/form-data` will be set, if no `Content-type` ! header is provided. If both `form` and `file` members are provided, then `file` ! and the `form` is sent as part of the body. having default `Content-type` header with value `multipart/form-data` ! if no `Content-type` header is provided. ! If data, form, and file are all provided, only data is sent and the form and file ! inputs are ignored. ! ! If only `form` member is provided then `form` data is URL encoded and sent ! as the body of the request. and a default `Content-type` header with value ! `application/x-www-form-urlencoded` will be set, if no `Content-type` header is ! provided ! ! ! data -> data ! form -> form ! file -> file ! data + form + file -> data ! form + file -> form + file (in multipart/form-data) ! ! Note : At a time only one file can be send function set_body ( curl_ptr , request ) result ( status ) !!> The function sets the request `body`. !!____ !!> This function determines and set the type of data to include in the `request body` !!> based on the inputs provided to the `request()` procedure. !!> The function handles different combinations of `data`, `file`, and `form` members !!> to decide the content and the default header for the request body. !!> - If `data` member is provided, it takes the highest priority and is sent as the !!> body of the request. Any other provided `file` or `form` members will be ignored, !!> and only the `data` member will be included in the request body. !!> - If only the `file` member is provided, the `file` is sent as the body of the request. !!> If no `Content-type` header is provided, a default `Content-type` header with value !!> `multipart/form-data` will be set. !!> - If only the `form` member is provided, the `form` data is URL encoded and sent as !!> the body of the request. If no `Content-type` header is provided, a default `Content-type` !!> header with value `application/x-www-form-urlencoded` will be set. !!> - If both `form` and `file` members are provided, both `form` and `file` data are included !!> as part of the request body. A default `Content-type` header with value `multipart/form-data` !!> will be set if no `Content-type` header is provided. !!> - If `data`, `form`, and `file` are all provided, only `data` is sent, and the `form` and `file` !!> inputs are ignored. !!> ### **Combination Behavior Table** !!> | Passed Arguments | Request Body | Default Header | Behavior | !! |--------------------|---------------------------------|-------------------------------|---------------------------------------------------------| !! | data | data | None | The `data` is sent as the body of the request. | !! | file | file | multipart/form-data | The `file` is sent as the body of the request with the default header. | !! | form | Form data URL encoded | application/x-www-form-urlencoded | The `form` data is sent as the body of the request with the default header. | !! | data + file | data (file ignored) | None | The `file` member is ignored, and the `data` is sent as the body of the request. | !! | data + form | data (form ignored) | None | The `form` member is ignored, and the `data` is sent as the body of the request. | !! | file + form | both file and form | multipart/form-data | Both `form` and `file` are sent as part of the request. | !! | data + file + form | data (form and file ignored) | None | Both `form` and `file` members are ignored, and only the `data` is sent as the body of the request. | !!> Note: If custom headers are provided in the `headers` parameter, they will be used. Otherwise, default headers will be applied as mentioned in the table. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer value representing the status of the function call. integer :: i type ( c_ptr ) :: mime_ptr , part_ptr ! if only data is passed if ( allocated ( request % data )) then status = set_postfields ( curl_ptr , request % data ) ! if file is passsed else if ( allocated ( request % file )) then mime_ptr = curl_mime_init ( curl_ptr ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_filedata ( part_ptr , request % file % value ) status = curl_mime_name ( part_ptr , request % file % name ) ! if both file and form are passed if ( allocated ( request % form )) then do i = 1 , size ( request % form ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_data ( part_ptr , request % form ( i )% value , CURL_ZERO_TERMINATED ) status = curl_mime_name ( part_ptr , request % form ( i )% name ) end do end if status = curl_easy_setopt ( curl_ptr , CURLOPT_MIMEPOST , mime_ptr ) ! setting the Content-Type header to multipart/form-data, used for sending binary data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'multipart/form-data' ) end if ! if only form is passed else if ( allocated ( request % form )) then request % form_encoded_str = prepare_form_encoded_str ( curl_ptr , request ) status = set_postfields ( curl_ptr , request % form_encoded_str ) ! setting the Content-Type header to application/x-www-form-urlencoded, used for sending form data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'application/x-www-form-urlencoded' ) end if else ! No curl function was called so set status to zero. status = 0 end if end function set_body function set_postfields ( curl_ptr , data ) result ( status ) !!> Set the data to be sent in the HTTP POST request body. !!____ !!> Use as helper function by `set_body` procedure to set request body type ( c_ptr ), intent ( inout ) :: curl_ptr !! Pointer to the CURL handle. character ( * ), intent ( in ), target :: data !! The data to be sent in the request body. integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDS , c_loc ( data )) status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDSIZE_LARGE , len ( data , kind = int64 )) end function set_postfields function set_auth ( curl_ptr , request ) result ( status ) !!> Set the user name and password for Authentication. !!_____ !!> It sends the user name and password over the network in plain text, easily captured by others. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the CURL handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). if ( allocated ( request % auth )) then status = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) status = curl_easy_setopt ( curl_ptr , CURLOPT_USERNAME , request % auth % name ) status = curl_easy_setopt ( curl_ptr , CURLOPT_PASSWORD , request % auth % value ) else ! No curl function was called so set status to zero. status = 0 end if end function set_auth function client_response_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the fortran-curl package to handle HTTP responses. !!> It is called for each `chunk` of data received from the server and appends the data to a !!> `response_type` object. !!>_____ !!> It is called for each `chunk` of data received from the server and appends the data to a `response_type` !!> object passed(i.e `client_data`). The function takes four input arguments: `ptr`, `size`, `nmemb`, !!> and `client_data`. `ptr` is a pointer to the received data buffer, `size` specifies the size of each !!> data element, `nmemb` specifies the number of data elements received, and `client_data` is a pointer to !!> a `response_type` object. The function uses `c_f_pointer` to convert the C pointer to a Fortran pointer and !!> appends the received data to the `content` field of the `response_type` object. The function returns an integer !!> value representing the **number of bytes received.** type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each data element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of data elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Points to a response_type object. integer ( kind = c_size_t ) :: client_response_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf client_response_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) if (. not . allocated ( response % content )) response % content = '' ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return response % content = response % content // buf deallocate ( buf ) response % content_length = response % content_length + nmemb ! Return number of received bytes. client_response_callback = nmemb end function client_response_callback function client_header_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the `fortran-curl` package to handle HTTP headers. !!>_____ !!> It is called for each header received from the server and stores the header in an `header` member !!> of `response_type` object. type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. that points to the received header buffer. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each header element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of header elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Pointer to a `response_type` object. integer ( kind = c_size_t ) :: client_header_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf , h_name , h_value integer :: i client_header_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return ! Parsing Header, and storing in array of pair_type object i = index ( buf , ':' ) if ( i /= 0 . and . len ( buf ) > 2 ) then h_name = trim ( buf (: i - 1 )) h_value = buf ( i + 2 : ) h_value = h_value ( : len ( h_value ) - 2 ) if ( len ( h_value ) > 0 . and . len ( h_name ) > 0 ) then call append_pair ( response % header , h_name , h_value ) ! response%header = [response%header, pair_type(h_name, h_value)] end if end if deallocate ( buf ) ! Return number of received bytes. client_header_callback = nmemb end function client_header_callback end module http_client","tags":"","loc":"sourcefile/http_client.f90.html"},{"title":"http_pair.f90 – HTTP","text":"This file contains the pair_type derived type, designed to \nstore various details like headers , file information, form-data , \nand authentication details. Contents Modules http_pair Source Code http_pair.f90 Source Code !!> This file contains the **`pair_type`** derived type, designed to !!> store various details like `headers`, `file` information, `form-data`, !!> and `authentication` details. module http_pair !!> This module contains the **`pair_type`** derived type, designed to !!> store various details like `headers`, `file` information, `form-data`, !!> and `authentication` details. use stdlib_ascii , only : to_lower implicit none private public :: pair_type public :: append_pair public :: get_pair_value public :: pair_has_name type :: pair_type !!> A derived type use to store a **name-value pair**. !!>____ !!>It is used in many instances like: !!> !!>1. Storing request and response `headers`: !!> - `name` to represent the header name. !!> - `value` to represent the header value. !!> !!>2. Representing fields in a url-encoded **HTTP `form`**: !!> - `name` to represent the form field name. !!> - `value` to represent the form field value. !!> !!>3. Storing information about the `file` to upload: !!> - `name` to represent the name of the file. !!> - `value` to represent the path of the file on the local system. !!> !!>4. Storing authentication detail, require to authenticate the request. !!> - `name` to represent the **username** !!> - `value` to represent the **password** character (:), allocatable :: name !! Name (key) character (:), allocatable :: value !! Value end type pair_type contains subroutine append_pair ( pair , name , value ) !!> Appends a new `pair_type` instance with the provided `name` !!> and `value` into the given `pair_type array`(i.e pair). type ( pair_type ), allocatable , intent ( inout ) :: pair (:) !! An array of `pair_type` objects, to which a new instance of `pair_type` needs to be added. character ( * ), intent ( in ) :: name !! The `name` attribute of the `pair_type` to be added. character ( * ), intent ( in ) :: value !! The `value` attribute of the `pair_type` to be added. type ( pair_type ), allocatable :: temp (:) integer :: n if ( allocated ( pair )) then n = size ( pair ) allocate ( temp ( n + 1 )) temp ( 1 : n ) = pair temp ( n + 1 ) = pair_type ( name , value ) call move_alloc ( temp , pair ) else allocate ( pair ( 1 )) pair ( 1 ) = pair_type ( name , value ) end if end subroutine append_pair pure function get_pair_value ( pair_arr , name ) result ( val ) !!> The function retrieves the `value` associated with a specified !!> `name` from the passed array of `pair_type` objects (i.e., pair_arr). !!> The search for the `name` is **case-insensitive**. If the `name` is !!> not found, the function returns an **unallocated string**. In the case !!> of duplicate `name` entries in the `pair_arr`, the function returns the !!> `value` of the **first occurrence** of the `name`. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. character (:), allocatable :: val !! Stores the `value` of the corresponding `pair_type` object whose `name` !! attribute is equal to the given `name`. integer :: n do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then val = pair_arr ( n )% value return end if end do end function get_pair_value pure logical function pair_has_name ( pair_arr , name ) !!> Return `.true.` if there exists a `pair_type` object inside `pair_arr` with !!> a `name` attribute equal to the provided `name`; otherwise, return `.false.`. !!> HTTP pairs are **case-insensitive**, implying that values are **converted to !!> lowercase** before the comparison is performed. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. integer :: n pair_has_name = . false . do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then pair_has_name = . true . return end if end do end function pair_has_name end module http_pair","tags":"","loc":"sourcefile/http_pair.f90.html"}]}
\ No newline at end of file
+var tipuesearch = {"pages":[{"title":" HTTP ","text":"HTTP http-client http-client is Fortran library to make HTTP requests.\nIt simplifies interacting with web services by providing a high-level and\nuser-friendly interface. Features HTTP request methods: GET : Retrieve data from the server. POST : Create new data the server. PUT : Replace an existing resource on the server. DELETE : Delete a resource from the server. PATCH : Partially update a resource on the server. HEAD : Get response headers without the response content. Supported data types: URL encoded fields HTTP form data File uploads Response handling: Retrieve response body (content). Get the HTTP status code returned by the server. Access response headers. Setting custom request headers Error handling with informative error messages Setting request timeouts Basic HTTP authentication Installation Before building the http-client library, ensure that you have the necessary\ndependencies installed. On Ubuntu, you need to install the curl development\nheaders. Use the following command: sudo apt install -y libcurl4-openssl-dev To use http-client as a dependency in your fpm project, add the following to\nyour the fpm.toml file of your package: [dependencies] http = { git = \"https://github.com/fortran-lang/http-client.git\" } stdlib = \"*\" Example use The following example demonstrates how to use http-client to make a simple GET request and process the response: program simple_get use http , only : response_type , request implicit none type ( response_type ) :: response ! Send a GET request to retrieve JSON data response = request ( url = 'https://jsonplaceholder.typicode.com/todos/1' ) ! 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 program simple_get Ouptut: Response Code : 200\n Response Length : 83\n Response Method : GET\n Response Content : {\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n} In this example, we make a GET request to the URL\nhttps://jsonplaceholder.typicode.com/todos/1 to retrieve JSON data.\nIf the request is successful, we print the response code, content length,\nmethod, and content. If the request fails, we print the error message. Getting Started Guides To begin your journey with our package, dive into the comprehensive tutorial\navailable here: tutorial.md . Projects using http-client github-org-analyzer :\nAn example mini-project to demonstrate the use of http-client by downloading\nand parsing data from the GitHub API. fortran-xkcd :\nAn fpm example project that displays the latest xkcd comic inside an X window.\nAs a limitation, only images in PNG format are supported.\nThe alt text will be printed to console. foropenai : A Fortran library to access the OpenAI API. fortelegram-bot : An Example of simple telegram bot forcompile : A Fortran library to access the Compiler Explorer API. If you're using http-client in your Fortran project and would like to be\nincluded on this list, we welcome you to contribute by creating a pull request\n(PR) and adding your project details. Contributing to project Thank you for your interest in http-client! Contributions from the community\nare esential for improving the package. This section provides a guide on how to\nget the code, build the library, and run examples and tests. Get the code To get started, follow these steps: Clone the repository using Git: git clone https://github.com/fortran-lang/http-client\ncd http-client Prerequisites Before building the library, ensure that you have the necessary dependencies\ninstalled. On Ubuntu, you need to install the curl development headers.\nUse the following command: sudo apt install -y libcurl4-openssl-dev Build the library http-client uses fpm as the build system. Make sure you have fpm-0.8.x or\nlater installed. To build the library, run the following command within the\nproject directory: fpm build Run examples http-client provides example programs that demonstrate its use. To run the\nexamples, use the following command: fpm run --example Executing this command will execute the example programs, allowing you to see\nthe package in action and understand how to utilize its features. Run tests http-client includes a test suite to ensure its functionality is working as\nexpected. To run the tests, type: fpm test Running the tests will validate the behavior of the package and help identify\nany issues or regressions. Generating API Documentation Before generating API documentation, ensure that you have FORD installed on your system . Once FORD is set up, execute the following command to build the API documentation: ford ford.md Supported compilers http-client is known to work with the following compilers: GFortran 11 & 12 (tested in CI) Intel OneAPI ifx v2023.1.0 and ifort classic v2021.9.0 Contributing guidelines When contributing to the http Fortran package, please keep the following guidelines in mind: Before making any substantial changes, it is recommended to open an issue to discuss the proposed changes and ensure they align with the project's goals. Fork the repository and create a new branch for your contribution. Ensure that your code adheres to the existing coding style and follows good software engineering practices. Write clear and concise commit messages. Make sure to test your changes and ensure they do not introduce regressions or break existing functionality. Submit a pull request with your changes, providing a clear explanation of the problem you are solving and the approach you have taken. We appreciate your contributions and look forward to your valuable input in improving http-client. Happy coding!👋 Developer Info Rajkumar Dongre Just Love to build Things 🛠️","tags":"home","loc":"index.html"},{"title":"response_type – HTTP ","text":"type, public :: response_type Representing an HTTP response . Contents Variables url content method err_msg status_code content_length ok header Type-Bound Procedures header_value Source Code response_type Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: content The content of the response. character(len=:), public, allocatable :: method The HTTP method of the request. character(len=:), public, allocatable :: err_msg The Error message if the response was not successful. integer, public :: status_code = 0 The HTTP status code of the response integer(kind=int64), public :: content_length = 0 length of the response content. logical, public :: ok = .true. true if the response was successful else false. type( pair_type ), public, allocatable :: header (:) An Array of response headers. Type-Bound Procedures procedure, public, :: header_value private pure function header_value (this, name) result(val) This function is used to retrieve the value of a response header. \nIt takes the response header name as input and returns the corresponding header value . Arguments Type Intent Optional Attributes Name class( response_type ), intent(in) :: this An object representing the HTTP response. character(len=*), intent(in) :: name This refers to the name of the header for which we want to retrieve the value. Return Value character(len=:), allocatable This denotes the value of the specified header name. Source Code type :: response_type !!> Representing an **HTTP `response`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: content !! The content of the response. character ( len = :), allocatable :: method !! The HTTP method of the request. character ( len = :), allocatable :: err_msg !! The Error message if the response was not successful. integer :: status_code = 0 !! The HTTP status code of the response integer ( kind = int64 ) :: content_length = 0 !! length of the response content. logical :: ok = . true . !! true if the response was successful else false. type ( pair_type ), allocatable :: header (:) !! An Array of response headers. contains procedure :: header_value end type response_type","tags":"","loc":"type/response_type.html"},{"title":"pair_type – HTTP ","text":"type, public :: pair_type A derived type use to store a name-value pair . It is used in many instances like: Storing request and response headers : name to represent the header name. value to represent the header value. Representing fields in a url-encoded HTTP form : name to represent the form field name. value to represent the form field value. Storing information about the file to upload: name to represent the name of the file. value to represent the path of the file on the local system. Storing authentication detail, require to authenticate the request. name to represent the username value to represent the password Contents Variables name value Source Code pair_type Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: name Name (key) character(len=:), public, allocatable :: value Value Source Code type :: pair_type !!> A derived type use to store a **name-value pair**. !!>____ !!>It is used in many instances like: !!> !!>1. Storing request and response `headers`: !!> - `name` to represent the header name. !!> - `value` to represent the header value. !!> !!>2. Representing fields in a url-encoded **HTTP `form`**: !!> - `name` to represent the form field name. !!> - `value` to represent the form field value. !!> !!>3. Storing information about the `file` to upload: !!> - `name` to represent the name of the file. !!> - `value` to represent the path of the file on the local system. !!> !!>4. Storing authentication detail, require to authenticate the request. !!> - `name` to represent the **username** !!> - `value` to represent the **password** character (:), allocatable :: name !! Name (key) character (:), allocatable :: value !! Value end type pair_type","tags":"","loc":"type/pair_type.html"},{"title":"client_type – HTTP ","text":"type, private :: client_type A derived type, responsible for making actual HTTP request using\nfortran-curl at backend. Contents Variables request Constructor client_type Type-Bound Procedures client_get_response Source Code client_type Components Type Visibility Attributes Name Initial type( request_type ), public :: request Constructor private interface client_type Interface for new_client function. private function new_client (request) result(client) This is the constructor for the client_type derived type. Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. Type-Bound Procedures procedure, public, :: client_get_response private function client_get_response (this) result(response) This function sends an HTTP request to a server using the fortran-curl package \nand stores the server's response in a response_type object. Arguments Type Intent Optional Attributes Name class( client_type ), intent(inout) :: this Contains the HTTP request to send. Return Value type( response_type ), target Contains the server's response . Source Code type :: client_type !!> A derived type, responsible for making **actual HTTP `request`** using !!> fortran-curl at backend. type ( request_type ) :: request contains procedure :: client_get_response end type client_type","tags":"","loc":"type/client_type.html"},{"title":"request_type – HTTP ","text":"type, public :: request_type Representing an HTTP request . Contents Variables url data form_encoded_str method header form file timeout auth Source Code request_type Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: data The data to be send with request character(len=:), public, allocatable :: form_encoded_str The URL-encoded form data. integer, public :: method The HTTP method of the request. type( pair_type ), public, allocatable :: header (:) An Array of request headers. type( pair_type ), public, allocatable :: form (:) An array of fields in an HTTP form. type( pair_type ), public, allocatable :: file Used to store information about files to be sent in HTTP requests. integer(kind=int64), public :: timeout Timeout value for the request in seconds . type( pair_type ), public, allocatable :: auth Stores the username and password for Authentication Source Code type :: request_type !! Representing an **HTTP `request`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: data !! The data to be send with request character ( len = :), allocatable :: form_encoded_str !! The URL-encoded form data. integer :: method !! The HTTP method of the request. type ( pair_type ), allocatable :: header (:) !! An Array of request headers. type ( pair_type ), allocatable :: form (:) !! An array of fields in an HTTP form. type ( pair_type ), allocatable :: file !! Used to store information about files to be sent in HTTP requests. integer ( kind = int64 ) :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), allocatable :: auth !! Stores the username and password for Authentication end type request_type","tags":"","loc":"type/request_type.html"},{"title":"header_value – HTTP","text":"private pure function header_value(this, name) result(val) This function is used to retrieve the value of a response header. \nIt takes the response header name as input and returns the corresponding header value . Type Bound response_type Arguments Type Intent Optional Attributes Name class( response_type ), intent(in) :: this An object representing the HTTP response. character(len=*), intent(in) :: name This refers to the name of the header for which we want to retrieve the value. Return Value character(len=:), allocatable This denotes the value of the specified header name. Contents Source Code header_value Source Code pure function header_value ( this , name ) result ( val ) !!> This function is used to retrieve the `value` of a response header. !!> It takes the response header `name` as input and returns the corresponding !!> **header value**. class ( response_type ), intent ( in ) :: this !! An object representing the HTTP response. character ( * ), intent ( in ) :: name !! This refers to the name of the header for which we want to retrieve the value. character (:), allocatable :: val !! This denotes the value of the specified header name. val = get_pair_value ( this % header , name ) end function header_value","tags":"","loc":"proc/header_value.html"},{"title":"get_pair_value – HTTP","text":"public pure function get_pair_value(pair_arr, name) result(val) The function retrieves the value associated with a specified name from the passed array of pair_type objects (i.e., pair_arr). \nThe search for the name is case-insensitive . If the name is \nnot found, the function returns an unallocated string . In the case \nof duplicate name entries in the pair_arr , the function returns the value of the first occurrence of the name . Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value character(len=:), allocatable Stores the value of the corresponding pair_type object whose name attribute is equal to the given name . Contents Source Code get_pair_value Source Code pure function get_pair_value ( pair_arr , name ) result ( val ) !!> The function retrieves the `value` associated with a specified !!> `name` from the passed array of `pair_type` objects (i.e., pair_arr). !!> The search for the `name` is **case-insensitive**. If the `name` is !!> not found, the function returns an **unallocated string**. In the case !!> of duplicate `name` entries in the `pair_arr`, the function returns the !!> `value` of the **first occurrence** of the `name`. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. character (:), allocatable :: val !! Stores the `value` of the corresponding `pair_type` object whose `name` !! attribute is equal to the given `name`. integer :: n do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then val = pair_arr ( n )% value return end if end do end function get_pair_value","tags":"","loc":"proc/get_pair_value.html"},{"title":"pair_has_name – HTTP","text":"public pure function pair_has_name(pair_arr, name) Return .true. if there exists a pair_type object inside pair_arr with \na name attribute equal to the provided name ; otherwise, return .false. . \nHTTP pairs are case-insensitive , implying that values are converted to \nlowercase before the comparison is performed. Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value logical Contents Source Code pair_has_name Source Code pure logical function pair_has_name ( pair_arr , name ) !!> Return `.true.` if there exists a `pair_type` object inside `pair_arr` with !!> a `name` attribute equal to the provided `name`; otherwise, return `.false.`. !!> HTTP pairs are **case-insensitive**, implying that values are **converted to !!> lowercase** before the comparison is performed. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. integer :: n pair_has_name = . false . do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then pair_has_name = . true . return end if end do end function pair_has_name","tags":"","loc":"proc/pair_has_name.html"},{"title":"append_pair – HTTP","text":"public subroutine append_pair(pair, name, value) Appends a new pair_type instance with the provided name and value into the given pair_type array (i.e pair). Arguments Type Intent Optional Attributes Name type( pair_type ), intent(inout), allocatable :: pair (:) An array of pair_type objects, to which a new instance of pair_type needs to be added. character(len=*), intent(in) :: name The name attribute of the pair_type to be added. character(len=*), intent(in) :: value The value attribute of the pair_type to be added. Contents Source Code append_pair Source Code subroutine append_pair ( pair , name , value ) !!> Appends a new `pair_type` instance with the provided `name` !!> and `value` into the given `pair_type array`(i.e pair). type ( pair_type ), allocatable , intent ( inout ) :: pair (:) !! An array of `pair_type` objects, to which a new instance of `pair_type` needs to be added. character ( * ), intent ( in ) :: name !! The `name` attribute of the `pair_type` to be added. character ( * ), intent ( in ) :: value !! The `value` attribute of the `pair_type` to be added. type ( pair_type ), allocatable :: temp (:) integer :: n if ( allocated ( pair )) then n = size ( pair ) allocate ( temp ( n + 1 )) temp ( 1 : n ) = pair temp ( n + 1 ) = pair_type ( name , value ) call move_alloc ( temp , pair ) else allocate ( pair ( 1 )) pair ( 1 ) = pair_type ( name , value ) end if end subroutine append_pair","tags":"","loc":"proc/append_pair.html"},{"title":"new_request – HTTP","text":"private function new_request(url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Note : If the header argument is not provided, default user-agent header is set to http-client/0.1 . Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response . Contents Source Code new_request Source Code function new_request ( url , method , header , data , form , file , timeout , auth ) result ( response ) !!> This function create a `request_type` object and populates it. !!> The function returns the `response_type` object containing the !!> **server's response**. !!____ !!> #### Note : !!> If the `header` argument is not provided, **default `user-agent` !!> header is set to `http-client/0.1`**. integer , intent ( in ), optional :: method !! Specifies the HTTP `method` to use for the request. !! The **default value is 1**, which corresponds to the **`HTTP_GET`** method. character ( len =* ), intent ( in ) :: url !! Specifies the **`URL`** of the server. character ( len =* ), intent ( in ), optional :: data !! Specifies the **`data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: header (:) !! Specifies the **request `headers`** that need to be sent to the server. type ( pair_type ), intent ( in ), optional :: form (:) !! Specifies the **`form data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: file !! Specifies the **`file`** that needs to be sent to the server. integer , intent ( in ), optional :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), intent ( in ), optional :: auth !! stores the `username` and `password` for **`authentication`** purposes. type ( response_type ) :: response !! Stores the server's **`response`**. type ( request_type ) :: request type ( client_type ) :: client integer :: i ! setting request url request % url = url ! Set default HTTP method. request % method = optval ( method , 1 ) ! Set request header if ( present ( header )) then request % header = header ! Set default request headers. if (. not . pair_has_name ( header , 'user-agent' )) then call append_pair ( request % header , 'user-agent' , 'http-client/' // VERSION_STRING ) end if else ! Set default request headers. request % header = [ pair_type ( 'user-agent' , 'http-client/' // VERSION_STRING )] end if ! setting the request data to be send if ( present ( data )) then request % data = data end if ! setting request form if ( present ( form )) then request % form = form end if ! setting request file if ( present ( file )) then request % file = file end if ! Set request timeout. request % timeout = optval ( timeout , - 1 ) ! setting username and password for Authentication if ( present ( auth )) then request % auth = auth end if ! Populates the response client = client_type ( request = request ) response = client % client_get_response () end function new_request","tags":"","loc":"proc/new_request.html"},{"title":"new_client – HTTP","text":"private function new_client(request) result(client) This is the constructor for the client_type derived type. Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. Contents Source Code new_client Source Code function new_client ( request ) result ( client ) !!> This is the constructor for the `client_type` derived type. type ( request_type ), intent ( in ) :: request !! Specifies the **HTTP `request`** to send. type ( client_type ) :: client !! A `client_type` object containing the `request` field set to the input `request` object. client % request = request end function new_client","tags":"","loc":"proc/new_client.html"},{"title":"client_get_response – HTTP","text":"private function client_get_response(this) result(response) This function sends an HTTP request to a server using the fortran-curl package \nand stores the server's response in a response_type object. Type Bound client_type Arguments Type Intent Optional Attributes Name class( client_type ), intent(inout) :: this Contains the HTTP request to send. Return Value type( response_type ), target Contains the server's response . Contents Source Code client_get_response Source Code function client_get_response ( this ) result ( response ) !!> This function sends an HTTP `request` to a server using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package !!> and stores the server's response in a `response_type` !!> object. class ( client_type ), intent ( inout ) :: this !! Contains the HTTP `request` to send. type ( response_type ), target :: response !! Contains the **server's response**. type ( c_ptr ) :: curl_ptr , header_list_ptr integer :: rc , i curl_ptr = c_null_ptr header_list_ptr = c_null_ptr response % url = this % request % url curl_ptr = curl_easy_init () if (. not . c_associated ( curl_ptr )) then response % ok = . false . response % err_msg = \"The initialization of a new easy handle using the 'curl_easy_init()'& & function failed. This can occur due to insufficient memory available in the system. & & Additionally, if libcurl is not installed or configured properly on the system\" return end if ! setting request URL rc = curl_easy_setopt ( curl_ptr , CURLOPT_URL , this % request % url ) ! setting request method rc = set_method ( curl_ptr , this % request % method , response ) ! setting request timeout rc = set_timeout ( curl_ptr , this % request % timeout ) ! setting request body rc = set_body ( curl_ptr , this % request ) ! setting request authentication rc = set_auth ( curl_ptr , this % request ) ! prepare headers for curl call prepare_request_header_ptr ( header_list_ptr , this % request % header ) ! setting request header rc = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPHEADER , header_list_ptr ); ! setting callback for writing received data rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEFUNCTION , c_funloc ( client_response_callback )) ! setting response content pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEDATA , c_loc ( response )) ! setting callback for writing received headers rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERFUNCTION , c_funloc ( client_header_callback )) ! setting response header pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERDATA , c_loc ( response )) ! Send request. rc = curl_easy_perform ( curl_ptr ) if ( rc /= CURLE_OK ) then response % ok = . false . response % err_msg = curl_easy_strerror ( rc ) end if ! setting response status_code rc = curl_easy_getinfo ( curl_ptr , CURLINFO_RESPONSE_CODE , response % status_code ) call curl_easy_cleanup ( curl_ptr ) end function client_get_response","tags":"","loc":"proc/client_get_response.html"},{"title":"prepare_form_encoded_str – HTTP","text":"private function prepare_form_encoded_str(curl_ptr, request) result(form_encoded_str) This subroutine converts the request%form into a URL-encoded name-value \nstring and returns it. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. type( request_type ), intent(inout) :: request The HTTP request to send, which includes the form data to be encoded. Return Value character(len=:), allocatable Stores the URL Encoded string . Contents Source Code prepare_form_encoded_str Source Code function prepare_form_encoded_str ( curl_ptr , request ) result ( form_encoded_str ) !!> This subroutine converts the `request%form` into a **URL-encoded name-value !!> string** and returns it. ! This subroutine takes a request object containing a list of name-value pairs ! representing the form data. It iterates over the list and URL-encodes each ! name and value using the curl_easy_escape function, which replaces special ! characters with their corresponding escape sequences. ! The encoded name-value pairs are concatenated into a single string, separated ! by '&' characters. The resulting string is returned type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. type ( request_type ), intent ( inout ) :: request !! The HTTP `request` to send, which includes the `form` data to be encoded. character (:), allocatable :: form_encoded_str !! Stores the **URL Encoded string**. integer :: i if ( allocated ( request % form )) then do i = 1 , size ( request % form ) if (. not . allocated ( form_encoded_str )) then form_encoded_str = curl_easy_escape ( curl_ptr , request % form ( i )% name , & len ( request % form ( i )% name )) // '=' // curl_easy_escape ( curl_ptr , & request % form ( i )% value , len ( request % form ( i )% value )) else form_encoded_str = form_encoded_str // '&' // & curl_easy_escape ( curl_ptr , request % form ( i )% name , len ( request % form ( i )% name ))& // '=' // curl_easy_escape ( curl_ptr , request % form ( i )% value , len ( request % form ( i )% value )) end if end do end if end function prepare_form_encoded_str","tags":"","loc":"proc/prepare_form_encoded_str.html"},{"title":"set_method – HTTP","text":"private function set_method(curl_ptr, method, response) result(status) This function sets the HTTP method for the request. The method argument can take one of the following values: HTTP_GET , HTTP_HEAD , HTTP_POST , HTTP_PUT , HTTP_DELETE , HTTP_PATCH . If any other value is provided, an error will be thrown . Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. integer, intent(in) :: method Specifies the HTTP method to use. type( response_type ), intent(out) :: response The HTTP response from the server. Return Value integer The status of setting HTTP method. Contents Source Code set_method Source Code function set_method ( curl_ptr , method , response ) result ( status ) !!> This function sets the **HTTP `method`** for the request. !!____ !!#### **The `method` argument can take one of the following values:** !!> `HTTP_GET`, `HTTP_HEAD`, `HTTP_POST`, `HTTP_PUT`, `HTTP_DELETE`, !!> `HTTP_PATCH`. If any other value is provided, an **error will be thrown**. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. integer , intent ( in ) :: method !! Specifies the HTTP `method` to use. type ( response_type ), intent ( out ) :: response !! The HTTP `response` from the server. integer :: status !! The `status` of setting HTTP method. select case ( method ) case ( 1 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'GET' ) response % method = 'GET' case ( 2 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'HEAD' ) response % method = 'HEAD' case ( 3 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'POST' ) response % method = 'POST' case ( 4 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PUT' ) response % method = 'PUT' case ( 5 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'DELETE' ) response % method = 'DELETE' case ( 6 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PATCH' ) response % method = 'PATCH' case default error stop 'Method argument can be either HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_PATCH' end select end function set_method","tags":"","loc":"proc/set_method.html"},{"title":"set_timeout – HTTP","text":"private function set_timeout(curl_ptr, timeout) result(status) This function sets the timeout value (in seconds) . If the timeout value is less than zero , it is ignored and a success status is returned. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. integer(kind=int64), intent(in) :: timeout Timeout seconds for request. Return Value integer Status code indicating whether the operation was successful. Contents Source Code set_timeout Source Code function set_timeout ( curl_ptr , timeout ) result ( status ) !!> This function sets the `timeout` value **(in seconds)**. !!> !!> If the `timeout` value is **less than zero**, it is ignored and a success status is returned. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. integer ( kind = int64 ), intent ( in ) :: timeout !! `Timeout` seconds for request. integer :: status !! `Status code` indicating whether the operation was successful. if ( timeout < 0 ) then status = 0 else ! setting the maximum time allowed for the connection to established.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_CONNECTTIMEOUT , timeout ) ! setting maximum time allowed for transfer operation.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_TIMEOUT , timeout ) end if end function set_timeout","tags":"","loc":"proc/set_timeout.html"},{"title":"set_body – HTTP","text":"private function set_body(curl_ptr, request) result(status) The function sets the request body . This function determines and set the type of data to include in the request body based on the inputs provided to the request() procedure. The function handles different combinations of data , file , and form members \nto decide the content and the default header for the request body. If data member is provided, it takes the highest priority and is sent as the \nbody of the request. Any other provided file or form members will be ignored, \nand only the data member will be included in the request body. If only the file member is provided, the file is sent as the body of the request. \nIf no Content-type header is provided, a default Content-type header with value multipart/form-data will be set. If only the form member is provided, the form data is URL encoded and sent as \nthe body of the request. If no Content-type header is provided, a default Content-type header with value application/x-www-form-urlencoded will be set. If both form and file members are provided, both form and file data are included \nas part of the request body. A default Content-type header with value multipart/form-data will be set if no Content-type header is provided. If data , form , and file are all provided, only data is sent, and the form and file inputs are ignored. Combination Behavior Table Passed Arguments Request Body Default Header Behavior data data None The data is sent as the body of the request. file file multipart/form-data The file is sent as the body of the request with the default header. form Form data URL encoded application/x-www-form-urlencoded The form data is sent as the body of the request with the default header. data + file data (file ignored) None The file member is ignored, and the data is sent as the body of the request. data + form data (form ignored) None The form member is ignored, and the data is sent as the body of the request. file + form both file and form multipart/form-data Both form and file are sent as part of the request. data + file + form data (form and file ignored) None Both form and file members are ignored, and only the data is sent as the body of the request. Note: If custom headers are provided in the headers parameter, they will be used. Otherwise, default headers will be applied as mentioned in the table. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer value representing the status of the function call. Contents Source Code set_body Source Code function set_body ( curl_ptr , request ) result ( status ) !!> The function sets the request `body`. !!____ !!> This function determines and set the type of data to include in the `request body` !!> based on the inputs provided to the `request()` procedure. !!> The function handles different combinations of `data`, `file`, and `form` members !!> to decide the content and the default header for the request body. !!> - If `data` member is provided, it takes the highest priority and is sent as the !!> body of the request. Any other provided `file` or `form` members will be ignored, !!> and only the `data` member will be included in the request body. !!> - If only the `file` member is provided, the `file` is sent as the body of the request. !!> If no `Content-type` header is provided, a default `Content-type` header with value !!> `multipart/form-data` will be set. !!> - If only the `form` member is provided, the `form` data is URL encoded and sent as !!> the body of the request. If no `Content-type` header is provided, a default `Content-type` !!> header with value `application/x-www-form-urlencoded` will be set. !!> - If both `form` and `file` members are provided, both `form` and `file` data are included !!> as part of the request body. A default `Content-type` header with value `multipart/form-data` !!> will be set if no `Content-type` header is provided. !!> - If `data`, `form`, and `file` are all provided, only `data` is sent, and the `form` and `file` !!> inputs are ignored. !!> ### **Combination Behavior Table** !!> | Passed Arguments | Request Body | Default Header | Behavior | !! |--------------------|---------------------------------|-------------------------------|---------------------------------------------------------| !! | data | data | None | The `data` is sent as the body of the request. | !! | file | file | multipart/form-data | The `file` is sent as the body of the request with the default header. | !! | form | Form data URL encoded | application/x-www-form-urlencoded | The `form` data is sent as the body of the request with the default header. | !! | data + file | data (file ignored) | None | The `file` member is ignored, and the `data` is sent as the body of the request. | !! | data + form | data (form ignored) | None | The `form` member is ignored, and the `data` is sent as the body of the request. | !! | file + form | both file and form | multipart/form-data | Both `form` and `file` are sent as part of the request. | !! | data + file + form | data (form and file ignored) | None | Both `form` and `file` members are ignored, and only the `data` is sent as the body of the request. | !!> Note: If custom headers are provided in the `headers` parameter, they will be used. Otherwise, default headers will be applied as mentioned in the table. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer value representing the status of the function call. integer :: i type ( c_ptr ) :: mime_ptr , part_ptr ! if only data is passed if ( allocated ( request % data )) then status = set_postfields ( curl_ptr , request % data ) ! if file is passsed else if ( allocated ( request % file )) then mime_ptr = curl_mime_init ( curl_ptr ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_filedata ( part_ptr , request % file % value ) status = curl_mime_name ( part_ptr , request % file % name ) ! if both file and form are passed if ( allocated ( request % form )) then do i = 1 , size ( request % form ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_data ( part_ptr , request % form ( i )% value , CURL_ZERO_TERMINATED ) status = curl_mime_name ( part_ptr , request % form ( i )% name ) end do end if status = curl_easy_setopt ( curl_ptr , CURLOPT_MIMEPOST , mime_ptr ) ! setting the Content-Type header to multipart/form-data, used for sending binary data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'multipart/form-data' ) end if ! if only form is passed else if ( allocated ( request % form )) then request % form_encoded_str = prepare_form_encoded_str ( curl_ptr , request ) status = set_postfields ( curl_ptr , request % form_encoded_str ) ! setting the Content-Type header to application/x-www-form-urlencoded, used for sending form data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'application/x-www-form-urlencoded' ) end if else ! No curl function was called so set status to zero. status = 0 end if end function set_body","tags":"","loc":"proc/set_body.html"},{"title":"set_postfields – HTTP","text":"private function set_postfields(curl_ptr, data) result(status) Set the data to be sent in the HTTP POST request body. Use as helper function by set_body procedure to set request body Arguments Type Intent Optional Attributes Name type(c_ptr), intent(inout) :: curl_ptr Pointer to the CURL handle. character(len=*), intent(in), target :: data The data to be sent in the request body. Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). Contents Source Code set_postfields Source Code function set_postfields ( curl_ptr , data ) result ( status ) !!> Set the data to be sent in the HTTP POST request body. !!____ !!> Use as helper function by `set_body` procedure to set request body type ( c_ptr ), intent ( inout ) :: curl_ptr !! Pointer to the CURL handle. character ( * ), intent ( in ), target :: data !! The data to be sent in the request body. integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDS , c_loc ( data )) status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDSIZE_LARGE , len ( data , kind = int64 )) end function set_postfields","tags":"","loc":"proc/set_postfields.html"},{"title":"set_auth – HTTP","text":"private function set_auth(curl_ptr, request) result(status) Set the user name and password for Authentication. It sends the user name and password over the network in plain text, easily captured by others. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the CURL handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). Contents Source Code set_auth Source Code function set_auth ( curl_ptr , request ) result ( status ) !!> Set the user name and password for Authentication. !!_____ !!> It sends the user name and password over the network in plain text, easily captured by others. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the CURL handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). if ( allocated ( request % auth )) then status = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) status = curl_easy_setopt ( curl_ptr , CURLOPT_USERNAME , request % auth % name ) status = curl_easy_setopt ( curl_ptr , CURLOPT_PASSWORD , request % auth % value ) else ! No curl function was called so set status to zero. status = 0 end if end function set_auth","tags":"","loc":"proc/set_auth.html"},{"title":"client_response_callback – HTTP","text":"private function client_response_callback(ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP responses. \nIt is called for each chunk of data received from the server and appends the data to a response_type object. It is called for each chunk of data received from the server and appends the data to a response_type object passed(i.e client_data ). The function takes four input arguments: ptr , size , nmemb , and client_data . ptr is a pointer to the received data buffer, size specifies the size of each \ndata element, nmemb specifies the number of data elements received, and client_data is a pointer to a response_type object. The function uses c_f_pointer to convert the C pointer to a Fortran pointer and \nappends the received data to the content field of the response_type object. The function returns an integer\nvalue representing the number of bytes received. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each data element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of data elements received. type(c_ptr), intent(in), value :: client_data Points to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. Contents Source Code client_response_callback Source Code function client_response_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the fortran-curl package to handle HTTP responses. !!> It is called for each `chunk` of data received from the server and appends the data to a !!> `response_type` object. !!>_____ !!> It is called for each `chunk` of data received from the server and appends the data to a `response_type` !!> object passed(i.e `client_data`). The function takes four input arguments: `ptr`, `size`, `nmemb`, !!> and `client_data`. `ptr` is a pointer to the received data buffer, `size` specifies the size of each !!> data element, `nmemb` specifies the number of data elements received, and `client_data` is a pointer to !!> a `response_type` object. The function uses `c_f_pointer` to convert the C pointer to a Fortran pointer and !!> appends the received data to the `content` field of the `response_type` object. The function returns an integer !!> value representing the **number of bytes received.** type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each data element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of data elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Points to a response_type object. integer ( kind = c_size_t ) :: client_response_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf client_response_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) if (. not . allocated ( response % content )) response % content = '' ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return response % content = response % content // buf deallocate ( buf ) response % content_length = response % content_length + nmemb ! Return number of received bytes. client_response_callback = nmemb end function client_response_callback","tags":"","loc":"proc/client_response_callback.html"},{"title":"client_header_callback – HTTP","text":"private function client_header_callback(ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP headers. It is called for each header received from the server and stores the header in an header member \nof response_type object. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. that points to the received header buffer. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each header element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of header elements received. type(c_ptr), intent(in), value :: client_data Pointer to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. Contents Source Code client_header_callback Source Code function client_header_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the `fortran-curl` package to handle HTTP headers. !!>_____ !!> It is called for each header received from the server and stores the header in an `header` member !!> of `response_type` object. type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. that points to the received header buffer. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each header element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of header elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Pointer to a `response_type` object. integer ( kind = c_size_t ) :: client_header_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf , h_name , h_value integer :: i client_header_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return ! Parsing Header, and storing in array of pair_type object i = index ( buf , ':' ) if ( i /= 0 . and . len ( buf ) > 2 ) then h_name = trim ( buf (: i - 1 )) h_value = buf ( i + 2 : ) h_value = h_value ( : len ( h_value ) - 2 ) if ( len ( h_value ) > 0 . and . len ( h_name ) > 0 ) then call append_pair ( response % header , h_name , h_value ) ! response%header = [response%header, pair_type(h_name, h_value)] end if end if deallocate ( buf ) ! Return number of received bytes. client_header_callback = nmemb end function client_header_callback","tags":"","loc":"proc/client_header_callback.html"},{"title":"prepare_request_header_ptr – HTTP","text":"private subroutine prepare_request_header_ptr(header_list_ptr, req_headers) This subroutine prepares headers in required format(Linked list) for an HTTP request. This subroutine prepares a linked list of headers for an HTTP request using the fortran-curl package. \nThe function takes an array of pair_type objects(i.e. req_headers ) that contain the key-value pairs of the headers to include in the request.\nIt iterates over the array and constructs a string for each header in the format key:value .\nThe subroutine then appends each string to the linked list using the curl_slist_append function.\nThe resulting linked list is returned via the header_list_ptr argument. Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: header_list_ptr A Pointer that is allocated and points to a linked list of headers. type( pair_type ), intent(in), allocatable :: req_headers (:) The headers to be included in the request. Contents Source Code prepare_request_header_ptr Source Code subroutine prepare_request_header_ptr ( header_list_ptr , req_headers ) !!> This subroutine prepares `headers` in required format(Linked list) for an HTTP request. !!____ !!> This subroutine prepares a **linked list** of `headers` for an HTTP request using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package. !!> The function takes an array of `pair_type` objects(i.e. `req_headers`) that contain the !!> **key-value** pairs of the headers to include in the request. !!> It iterates over the array and constructs a string for each header in the format **`key:value`**. !!> The subroutine then appends each string to the linked list using the `curl_slist_append` function. !!> The resulting linked list is returned via the `header_list_ptr` argument. type ( c_ptr ), intent ( out ) :: header_list_ptr !! A `Pointer` that is allocated and points to a linked list of headers. type ( pair_type ), allocatable , intent ( in ) :: req_headers (:) !! The `headers` to be included in the request. character (:), allocatable :: h_name , h_val , final_header_string integer :: i do i = 1 , size ( req_headers ) h_name = req_headers ( i )% name h_val = req_headers ( i )% value final_header_string = h_name // ':' // h_val header_list_ptr = curl_slist_append ( header_list_ptr , final_header_string ) end do end subroutine prepare_request_header_ptr","tags":"","loc":"proc/prepare_request_header_ptr.html"},{"title":"client_type – HTTP","text":"private interface client_type Interface for new_client function. Contents Module Procedures new_client Module Procedures private function new_client (request) result(client) This is the constructor for the client_type derived type. Read more… Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object.","tags":"","loc":"interface/client_type.html"},{"title":"request – HTTP","text":"public interface request Interface for new_request function. Contents Module Procedures new_request Module Procedures private function new_request (url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Read more… Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response .","tags":"","loc":"interface/request.html"},{"title":"http – HTTP","text":"This Module contains all High-level API for the HTTP package. \nWhen the http module is imported into the project, all these \nhigh-level functionalities become available for use. Uses http_pair http_request http_response http_client Contents None","tags":"","loc":"module/http.html"},{"title":"http_version – HTTP","text":"This module store information regarding version number of package Contents Variables VERSION_MAJOR VERSION_MINOR VERSION_STRING Variables Type Visibility Attributes Name Initial integer, public, parameter :: VERSION_MAJOR = 0 major version number integer, public, parameter :: VERSION_MINOR = 1 minor version number character(len=*), public, parameter :: VERSION_STRING = achar(VERSION_MAJOR+48)//'.'//achar(VERSION_MINOR+48) string representation of version number","tags":"","loc":"module/http_version.html"},{"title":"http_response – HTTP","text":"This module defines the response_type derived type, which \nrepresents an HTTP response from a web server. Uses iso_fortran_env stdlib_string_type http_pair Contents Derived Types response_type Functions header_value Derived Types type, public :: response_type Representing an HTTP response . Read more… Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: content The content of the response. character(len=:), public, allocatable :: method The HTTP method of the request. character(len=:), public, allocatable :: err_msg The Error message if the response was not successful. integer, public :: status_code = 0 The HTTP status code of the response integer(kind=int64), public :: content_length = 0 length of the response content. logical, public :: ok = .true. true if the response was successful else false. type( pair_type ), public, allocatable :: header (:) An Array of response headers. Type-Bound Procedures procedure\n , public\n, :: header_value Function Functions private pure function header_value (this, name) result(val) This function is used to retrieve the value of a response header. \nIt takes the response header name as input and returns the corresponding header value . Read more… Arguments Type Intent Optional Attributes Name class( response_type ), intent(in) :: this An object representing the HTTP response. character(len=*), intent(in) :: name This refers to the name of the header for which we want to retrieve the value. Return Value character(len=:), allocatable This denotes the value of the specified header name.","tags":"","loc":"module/http_response.html"},{"title":"http_pair – HTTP","text":"This module contains the pair_type derived type, designed to \nstore various details like headers , file information, form-data , \nand authentication details. Uses stdlib_ascii Contents Derived Types pair_type Functions get_pair_value pair_has_name Subroutines append_pair Derived Types type, public :: pair_type A derived type use to store a name-value pair . Read more… Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: name Name (key) character(len=:), public, allocatable :: value Value Functions public pure function get_pair_value (pair_arr, name) result(val) The function retrieves the value associated with a specified name from the passed array of pair_type objects (i.e., pair_arr). \nThe search for the name is case-insensitive . If the name is \nnot found, the function returns an unallocated string . In the case \nof duplicate name entries in the pair_arr , the function returns the value of the first occurrence of the name . Read more… Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value character(len=:), allocatable Stores the value of the corresponding pair_type object whose name attribute is equal to the given name . public pure function pair_has_name (pair_arr, name) Return .true. if there exists a pair_type object inside pair_arr with \na name attribute equal to the provided name ; otherwise, return .false. . \nHTTP pairs are case-insensitive , implying that values are converted to \nlowercase before the comparison is performed. Read more… Arguments Type Intent Optional Attributes Name type( pair_type ), intent(in) :: pair_arr (:) The array in which we want to find a pair_type instance with its name attribute equal to the given name . character(len=*), intent(in) :: name The name to be searched in the pair_arr . Return Value logical Subroutines public subroutine append_pair (pair, name, value) Appends a new pair_type instance with the provided name and value into the given pair_type array (i.e pair). Read more… Arguments Type Intent Optional Attributes Name type( pair_type ), intent(inout), allocatable :: pair (:) An array of pair_type objects, to which a new instance of pair_type needs to be added. character(len=*), intent(in) :: name The name attribute of the pair_type to be added. character(len=*), intent(in) :: value The value attribute of the pair_type to be added.","tags":"","loc":"module/http_pair.html"},{"title":"http_client – HTTP","text":"This module defines the client_type derived type, which handles the \nprocess of making HTTP requests . The actual HTTP requests are executed \nusing the Fortran-curl package as the underlying mechanism. Uses iso_fortran_env iso_c_binding stdlib_optval http_pair http_request http_response curl http_version Contents Interfaces client_type request Derived Types client_type Functions new_request new_client client_get_response prepare_form_encoded_str set_method set_timeout set_body set_postfields set_auth client_response_callback client_header_callback Subroutines prepare_request_header_ptr Interfaces private interface client_type Interface for new_client function. private function new_client (request) result(client) This is the constructor for the client_type derived type. Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. public interface request Interface for new_request function. private function new_request (url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Note : If the header argument is not provided, default user-agent header is set to http-client/0.1 . Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response . Derived Types type, private :: client_type A derived type, responsible for making actual HTTP request using\nfortran-curl at backend. Read more… Components Type Visibility Attributes Name Initial type( request_type ), public :: request Constructor Interface for new_client function. Read more… private\n\n \n function new_client (request) This is the constructor for the client_type derived type. Read more… Type-Bound Procedures procedure\n , public\n, :: client_get_response Function Functions private function new_request (url, method, header, data, form, file, timeout, auth) result(response) This function create a request_type object and populates it.\nThe function returns the response_type object containing the server's response . Read more… Arguments Type Intent Optional Attributes Name character(len=*), intent(in) :: url Specifies the URL of the server. integer, intent(in), optional :: method Specifies the HTTP method to use for the request. \nThe default value is 1 , which corresponds to the HTTP_GET method. type( pair_type ), intent(in), optional :: header (:) Specifies the request headers that need to be sent to the server. character(len=*), intent(in), optional :: data Specifies the data that needs to be sent to the server. type( pair_type ), intent(in), optional :: form (:) Specifies the form data that needs to be sent to the server. type( pair_type ), intent(in), optional :: file Specifies the file that needs to be sent to the server. integer, intent(in), optional :: timeout Timeout value for the request in seconds . type( pair_type ), intent(in), optional :: auth stores the username and password for authentication purposes. Return Value type( response_type ) Stores the server's response . private function new_client (request) result(client) This is the constructor for the client_type derived type. Read more… Arguments Type Intent Optional Attributes Name type( request_type ), intent(in) :: request Specifies the HTTP request to send. Return Value type( client_type ) A client_type object containing the request field set to the input request object. private function client_get_response (this) result(response) This function sends an HTTP request to a server using the fortran-curl package \nand stores the server's response in a response_type object. Read more… Arguments Type Intent Optional Attributes Name class( client_type ), intent(inout) :: this Contains the HTTP request to send. Return Value type( response_type ), target Contains the server's response . private function prepare_form_encoded_str (curl_ptr, request) result(form_encoded_str) This subroutine converts the request%form into a URL-encoded name-value \nstring and returns it. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. type( request_type ), intent(inout) :: request The HTTP request to send, which includes the form data to be encoded. Return Value character(len=:), allocatable Stores the URL Encoded string . private function set_method (curl_ptr, method, response) result(status) This function sets the HTTP method for the request. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handler. integer, intent(in) :: method Specifies the HTTP method to use. type( response_type ), intent(out) :: response The HTTP response from the server. Return Value integer The status of setting HTTP method. private function set_timeout (curl_ptr, timeout) result(status) This function sets the timeout value (in seconds) . Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. integer(kind=int64), intent(in) :: timeout Timeout seconds for request. Return Value integer Status code indicating whether the operation was successful. private function set_body (curl_ptr, request) result(status) The function sets the request body . Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the curl handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer value representing the status of the function call. private function set_postfields (curl_ptr, data) result(status) Set the data to be sent in the HTTP POST request body. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(inout) :: curl_ptr Pointer to the CURL handle. character(len=*), intent(in), target :: data The data to be sent in the request body. Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). private function set_auth (curl_ptr, request) result(status) Set the user name and password for Authentication. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: curl_ptr Pointer to the CURL handle. type( request_type ), intent(inout) :: request The HTTP request Return Value integer An integer indicating whether the operation was successful (0) or not (non-zero). private function client_response_callback (ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP responses. \nIt is called for each chunk of data received from the server and appends the data to a response_type object. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each data element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of data elements received. type(c_ptr), intent(in), value :: client_data Points to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. private function client_header_callback (ptr, size, nmemb, client_data) bind(c) This function is a callback function used by the fortran-curl package to handle HTTP headers. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(in), value :: ptr Pointer to the CURL handle. that points to the received header buffer. integer(kind=c_size_t), intent(in), value :: size Specifies the size of each header element. integer(kind=c_size_t), intent(in), value :: nmemb Specifies the number of header elements received. type(c_ptr), intent(in), value :: client_data Pointer to a response_type object. Return Value integer(kind=c_size_t) The number of bytes received. Subroutines private subroutine prepare_request_header_ptr (header_list_ptr, req_headers) This subroutine prepares headers in required format(Linked list) for an HTTP request. Read more… Arguments Type Intent Optional Attributes Name type(c_ptr), intent(out) :: header_list_ptr A Pointer that is allocated and points to a linked list of headers. type( pair_type ), intent(in), allocatable :: req_headers (:) The headers to be included in the request.","tags":"","loc":"module/http_client.html"},{"title":"http_request – HTTP","text":"This module defines the request_type derived type, which \nrepresents an HTTP request . Uses iso_fortran_env stdlib_string_type http_pair Contents Variables HTTP_GET HTTP_HEAD HTTP_POST HTTP_PUT HTTP_DELETE HTTP_PATCH Derived Types request_type Variables Type Visibility Attributes Name Initial integer, public, parameter :: HTTP_GET = 1 integer, public, parameter :: HTTP_HEAD = 2 integer, public, parameter :: HTTP_POST = 3 integer, public, parameter :: HTTP_PUT = 4 integer, public, parameter :: HTTP_DELETE = 5 integer, public, parameter :: HTTP_PATCH = 6 Derived Types type, public :: request_type Representing an HTTP request . Components Type Visibility Attributes Name Initial character(len=:), public, allocatable :: url The URL of the request character(len=:), public, allocatable :: data The data to be send with request character(len=:), public, allocatable :: form_encoded_str The URL-encoded form data. integer, public :: method The HTTP method of the request. type( pair_type ), public, allocatable :: header (:) An Array of request headers. type( pair_type ), public, allocatable :: form (:) An array of fields in an HTTP form. type( pair_type ), public, allocatable :: file Used to store information about files to be sent in HTTP requests. integer(kind=int64), public :: timeout Timeout value for the request in seconds . type( pair_type ), public, allocatable :: auth Stores the username and password for Authentication","tags":"","loc":"module/http_request.html"},{"title":"http.f90 – HTTP","text":"This file provides the High-Level API for the HTTP package. \nWhen the http module is imported into the project, all these \nhigh-level functionalities become available for use. Contents Modules http Source Code http.f90 Source Code !!> This file provides the **High-Level API** for the **`HTTP`** package. !!> When the `http` module is imported into the project, all these !!> high-level functionalities become available for use. module http !!> This Module contains all **High-level API** for the **`HTTP`** package. !!> When the `http` module is imported into the project, all these !!> high-level functionalities become available for use. use http_request , only : & HTTP_DELETE , HTTP_GET , HTTP_HEAD , HTTP_PATCH , HTTP_POST , HTTP_PUT use http_response , only : response_type use http_client , only : request use http_pair , only : pair_type end module http","tags":"","loc":"sourcefile/http.f90.html"},{"title":"http_version.f90 – HTTP","text":"This file provides details about the version number of the package. Contents Modules http_version Source Code http_version.f90 Source Code !!> This file provides details about the **`version number`** of the package. module http_version !!> This module store information regarding **`version`** !!> number of package integer , parameter , public :: VERSION_MAJOR = 0 !! major version number integer , parameter , public :: VERSION_MINOR = 1 !! minor version number character ( len =* ), parameter , public :: VERSION_STRING = achar ( VERSION_MAJOR + 48 ) // '.' // achar ( VERSION_MINOR + 48 ) !! string representation of version number end module http_version","tags":"","loc":"sourcefile/http_version.f90.html"},{"title":"http_response.f90 – HTTP","text":"This file defines the response_type derived type, which \nrepresents an HTTP response from a web server. Contents Modules http_response Source Code http_response.f90 Source Code !!> This file defines the **`response_type`** derived type, which !!> represents an **HTTP response** from a web server. module http_response !!> This module defines the **`response_type`** derived type, which !!> represents an **HTTP response** from a web server. use , intrinsic :: iso_fortran_env , only : int64 use http_pair , only : pair_type , get_pair_value use stdlib_string_type , only : string_type , to_lower , operator ( == ), char implicit none private public :: response_type ! Response Type type :: response_type !!> Representing an **HTTP `response`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: content !! The content of the response. character ( len = :), allocatable :: method !! The HTTP method of the request. character ( len = :), allocatable :: err_msg !! The Error message if the response was not successful. integer :: status_code = 0 !! The HTTP status code of the response integer ( kind = int64 ) :: content_length = 0 !! length of the response content. logical :: ok = . true . !! true if the response was successful else false. type ( pair_type ), allocatable :: header (:) !! An Array of response headers. contains procedure :: header_value end type response_type contains pure function header_value ( this , name ) result ( val ) !!> This function is used to retrieve the `value` of a response header. !!> It takes the response header `name` as input and returns the corresponding !!> **header value**. class ( response_type ), intent ( in ) :: this !! An object representing the HTTP response. character ( * ), intent ( in ) :: name !! This refers to the name of the header for which we want to retrieve the value. character (:), allocatable :: val !! This denotes the value of the specified header name. val = get_pair_value ( this % header , name ) end function header_value end module http_response","tags":"","loc":"sourcefile/http_response.f90.html"},{"title":"http_pair.f90 – HTTP","text":"This file contains the pair_type derived type, designed to \nstore various details like headers , file information, form-data , \nand authentication details. Contents Modules http_pair Source Code http_pair.f90 Source Code !!> This file contains the **`pair_type`** derived type, designed to !!> store various details like `headers`, `file` information, `form-data`, !!> and `authentication` details. module http_pair !!> This module contains the **`pair_type`** derived type, designed to !!> store various details like `headers`, `file` information, `form-data`, !!> and `authentication` details. use stdlib_ascii , only : to_lower implicit none private public :: pair_type public :: append_pair public :: get_pair_value public :: pair_has_name type :: pair_type !!> A derived type use to store a **name-value pair**. !!>____ !!>It is used in many instances like: !!> !!>1. Storing request and response `headers`: !!> - `name` to represent the header name. !!> - `value` to represent the header value. !!> !!>2. Representing fields in a url-encoded **HTTP `form`**: !!> - `name` to represent the form field name. !!> - `value` to represent the form field value. !!> !!>3. Storing information about the `file` to upload: !!> - `name` to represent the name of the file. !!> - `value` to represent the path of the file on the local system. !!> !!>4. Storing authentication detail, require to authenticate the request. !!> - `name` to represent the **username** !!> - `value` to represent the **password** character (:), allocatable :: name !! Name (key) character (:), allocatable :: value !! Value end type pair_type contains subroutine append_pair ( pair , name , value ) !!> Appends a new `pair_type` instance with the provided `name` !!> and `value` into the given `pair_type array`(i.e pair). type ( pair_type ), allocatable , intent ( inout ) :: pair (:) !! An array of `pair_type` objects, to which a new instance of `pair_type` needs to be added. character ( * ), intent ( in ) :: name !! The `name` attribute of the `pair_type` to be added. character ( * ), intent ( in ) :: value !! The `value` attribute of the `pair_type` to be added. type ( pair_type ), allocatable :: temp (:) integer :: n if ( allocated ( pair )) then n = size ( pair ) allocate ( temp ( n + 1 )) temp ( 1 : n ) = pair temp ( n + 1 ) = pair_type ( name , value ) call move_alloc ( temp , pair ) else allocate ( pair ( 1 )) pair ( 1 ) = pair_type ( name , value ) end if end subroutine append_pair pure function get_pair_value ( pair_arr , name ) result ( val ) !!> The function retrieves the `value` associated with a specified !!> `name` from the passed array of `pair_type` objects (i.e., pair_arr). !!> The search for the `name` is **case-insensitive**. If the `name` is !!> not found, the function returns an **unallocated string**. In the case !!> of duplicate `name` entries in the `pair_arr`, the function returns the !!> `value` of the **first occurrence** of the `name`. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. character (:), allocatable :: val !! Stores the `value` of the corresponding `pair_type` object whose `name` !! attribute is equal to the given `name`. integer :: n do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then val = pair_arr ( n )% value return end if end do end function get_pair_value pure logical function pair_has_name ( pair_arr , name ) !!> Return `.true.` if there exists a `pair_type` object inside `pair_arr` with !!> a `name` attribute equal to the provided `name`; otherwise, return `.false.`. !!> HTTP pairs are **case-insensitive**, implying that values are **converted to !!> lowercase** before the comparison is performed. type ( pair_type ), intent ( in ) :: pair_arr (:) !! The array in which we want to find a `pair_type` instance with its !! `name` attribute equal to the given `name`. character ( * ), intent ( in ) :: name !! The `name` to be searched in the `pair_arr`. integer :: n pair_has_name = . false . do n = 1 , size ( pair_arr ) if ( to_lower ( name ) == to_lower ( pair_arr ( n )% name )) then pair_has_name = . true . return end if end do end function pair_has_name end module http_pair","tags":"","loc":"sourcefile/http_pair.f90.html"},{"title":"http_client.f90 – HTTP","text":"This file defines the client_type derived type, which handles the \nprocess of making HTTP requests . The actual HTTP requests are executed \nusing the Fortran-curl package as the underlying mechanism. Contents Modules http_client Source Code http_client.f90 Source Code !!> This file defines the **`client_type`** derived type, which handles the !!> process of making **HTTP requests**. The actual HTTP requests are executed !!> using the [Fortran-curl](https://github.com/interkosmos/fortran-curl) !!> package as the underlying mechanism. module http_client !!> This module defines the **`client_type`** derived type, which handles the !!> process of making **HTTP requests**. The actual HTTP requests are executed !!> using the [Fortran-curl](https://github.com/interkosmos/fortran-curl) !!> package as the underlying mechanism. use iso_fortran_env , only : int64 use iso_c_binding , only : c_associated , c_f_pointer , c_funloc , c_loc , & c_null_ptr , c_ptr , c_size_t , c_null_char use curl , only : c_f_str_ptr , curl_easy_cleanup , curl_easy_getinfo , & curl_easy_init , curl_easy_perform , curl_easy_setopt , & curl_easy_strerror , curl_slist_append , CURLE_OK , & CURLINFO_RESPONSE_CODE , CURLOPT_CUSTOMREQUEST , CURLOPT_HEADERDATA , & CURLOPT_HEADERFUNCTION , CURLOPT_HTTPHEADER , CURLOPT_URL , & CURLOPT_WRITEDATA , CURLOPT_WRITEFUNCTION , & CURLOPT_POSTFIELDS , CURLOPT_POSTFIELDSIZE_LARGE , curl_easy_escape , & curl_mime_init , curl_mime_addpart , curl_mime_filedata , curl_mime_name , & CURLOPT_MIMEPOST , curl_mime_data , CURL_ZERO_TERMINATED , & CURLOPT_TIMEOUT , CURLOPT_CONNECTTIMEOUT , & CURLOPT_HTTPAUTH , CURLAUTH_BASIC , CURLOPT_USERNAME , CURLOPT_PASSWORD use stdlib_optval , only : optval use http_request , only : request_type use http_response , only : response_type use http_pair , only : append_pair , pair_has_name , pair_type use http_version , only : VERSION_STRING implicit none private public :: request ! http_client Type type :: client_type !!> A derived type, responsible for making **actual HTTP `request`** using !!> fortran-curl at backend. type ( request_type ) :: request contains procedure :: client_get_response end type client_type interface client_type !!> Interface for `new_client` function. module procedure new_client end interface client_type interface request !!> Interface for `new_request` function. module procedure new_request end interface request contains function new_request ( url , method , header , data , form , file , timeout , auth ) result ( response ) !!> This function create a `request_type` object and populates it. !!> The function returns the `response_type` object containing the !!> **server's response**. !!____ !!> #### Note : !!> If the `header` argument is not provided, **default `user-agent` !!> header is set to `http-client/0.1`**. integer , intent ( in ), optional :: method !! Specifies the HTTP `method` to use for the request. !! The **default value is 1**, which corresponds to the **`HTTP_GET`** method. character ( len =* ), intent ( in ) :: url !! Specifies the **`URL`** of the server. character ( len =* ), intent ( in ), optional :: data !! Specifies the **`data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: header (:) !! Specifies the **request `headers`** that need to be sent to the server. type ( pair_type ), intent ( in ), optional :: form (:) !! Specifies the **`form data`** that needs to be sent to the server. type ( pair_type ), intent ( in ), optional :: file !! Specifies the **`file`** that needs to be sent to the server. integer , intent ( in ), optional :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), intent ( in ), optional :: auth !! stores the `username` and `password` for **`authentication`** purposes. type ( response_type ) :: response !! Stores the server's **`response`**. type ( request_type ) :: request type ( client_type ) :: client integer :: i ! setting request url request % url = url ! Set default HTTP method. request % method = optval ( method , 1 ) ! Set request header if ( present ( header )) then request % header = header ! Set default request headers. if (. not . pair_has_name ( header , 'user-agent' )) then call append_pair ( request % header , 'user-agent' , 'http-client/' // VERSION_STRING ) end if else ! Set default request headers. request % header = [ pair_type ( 'user-agent' , 'http-client/' // VERSION_STRING )] end if ! setting the request data to be send if ( present ( data )) then request % data = data end if ! setting request form if ( present ( form )) then request % form = form end if ! setting request file if ( present ( file )) then request % file = file end if ! Set request timeout. request % timeout = optval ( timeout , - 1 ) ! setting username and password for Authentication if ( present ( auth )) then request % auth = auth end if ! Populates the response client = client_type ( request = request ) response = client % client_get_response () end function new_request function new_client ( request ) result ( client ) !!> This is the constructor for the `client_type` derived type. type ( request_type ), intent ( in ) :: request !! Specifies the **HTTP `request`** to send. type ( client_type ) :: client !! A `client_type` object containing the `request` field set to the input `request` object. client % request = request end function new_client function client_get_response ( this ) result ( response ) !!> This function sends an HTTP `request` to a server using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package !!> and stores the server's response in a `response_type` !!> object. class ( client_type ), intent ( inout ) :: this !! Contains the HTTP `request` to send. type ( response_type ), target :: response !! Contains the **server's response**. type ( c_ptr ) :: curl_ptr , header_list_ptr integer :: rc , i curl_ptr = c_null_ptr header_list_ptr = c_null_ptr response % url = this % request % url curl_ptr = curl_easy_init () if (. not . c_associated ( curl_ptr )) then response % ok = . false . response % err_msg = \"The initialization of a new easy handle using the 'curl_easy_init()'& & function failed. This can occur due to insufficient memory available in the system. & & Additionally, if libcurl is not installed or configured properly on the system\" return end if ! setting request URL rc = curl_easy_setopt ( curl_ptr , CURLOPT_URL , this % request % url ) ! setting request method rc = set_method ( curl_ptr , this % request % method , response ) ! setting request timeout rc = set_timeout ( curl_ptr , this % request % timeout ) ! setting request body rc = set_body ( curl_ptr , this % request ) ! setting request authentication rc = set_auth ( curl_ptr , this % request ) ! prepare headers for curl call prepare_request_header_ptr ( header_list_ptr , this % request % header ) ! setting request header rc = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPHEADER , header_list_ptr ); ! setting callback for writing received data rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEFUNCTION , c_funloc ( client_response_callback )) ! setting response content pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_WRITEDATA , c_loc ( response )) ! setting callback for writing received headers rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERFUNCTION , c_funloc ( client_header_callback )) ! setting response header pointer to write callback rc = curl_easy_setopt ( curl_ptr , CURLOPT_HEADERDATA , c_loc ( response )) ! Send request. rc = curl_easy_perform ( curl_ptr ) if ( rc /= CURLE_OK ) then response % ok = . false . response % err_msg = curl_easy_strerror ( rc ) end if ! setting response status_code rc = curl_easy_getinfo ( curl_ptr , CURLINFO_RESPONSE_CODE , response % status_code ) call curl_easy_cleanup ( curl_ptr ) end function client_get_response function prepare_form_encoded_str ( curl_ptr , request ) result ( form_encoded_str ) !!> This subroutine converts the `request%form` into a **URL-encoded name-value !!> string** and returns it. ! This subroutine takes a request object containing a list of name-value pairs ! representing the form data. It iterates over the list and URL-encodes each ! name and value using the curl_easy_escape function, which replaces special ! characters with their corresponding escape sequences. ! The encoded name-value pairs are concatenated into a single string, separated ! by '&' characters. The resulting string is returned type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. type ( request_type ), intent ( inout ) :: request !! The HTTP `request` to send, which includes the `form` data to be encoded. character (:), allocatable :: form_encoded_str !! Stores the **URL Encoded string**. integer :: i if ( allocated ( request % form )) then do i = 1 , size ( request % form ) if (. not . allocated ( form_encoded_str )) then form_encoded_str = curl_easy_escape ( curl_ptr , request % form ( i )% name , & len ( request % form ( i )% name )) // '=' // curl_easy_escape ( curl_ptr , & request % form ( i )% value , len ( request % form ( i )% value )) else form_encoded_str = form_encoded_str // '&' // & curl_easy_escape ( curl_ptr , request % form ( i )% name , len ( request % form ( i )% name ))& // '=' // curl_easy_escape ( curl_ptr , request % form ( i )% value , len ( request % form ( i )% value )) end if end do end if end function prepare_form_encoded_str subroutine prepare_request_header_ptr ( header_list_ptr , req_headers ) !!> This subroutine prepares `headers` in required format(Linked list) for an HTTP request. !!____ !!> This subroutine prepares a **linked list** of `headers` for an HTTP request using the !!> [fortran-curl](https://github.com/interkosmos/fortran-curl) package. !!> The function takes an array of `pair_type` objects(i.e. `req_headers`) that contain the !!> **key-value** pairs of the headers to include in the request. !!> It iterates over the array and constructs a string for each header in the format **`key:value`**. !!> The subroutine then appends each string to the linked list using the `curl_slist_append` function. !!> The resulting linked list is returned via the `header_list_ptr` argument. type ( c_ptr ), intent ( out ) :: header_list_ptr !! A `Pointer` that is allocated and points to a linked list of headers. type ( pair_type ), allocatable , intent ( in ) :: req_headers (:) !! The `headers` to be included in the request. character (:), allocatable :: h_name , h_val , final_header_string integer :: i do i = 1 , size ( req_headers ) h_name = req_headers ( i )% name h_val = req_headers ( i )% value final_header_string = h_name // ':' // h_val header_list_ptr = curl_slist_append ( header_list_ptr , final_header_string ) end do end subroutine prepare_request_header_ptr function set_method ( curl_ptr , method , response ) result ( status ) !!> This function sets the **HTTP `method`** for the request. !!____ !!#### **The `method` argument can take one of the following values:** !!> `HTTP_GET`, `HTTP_HEAD`, `HTTP_POST`, `HTTP_PUT`, `HTTP_DELETE`, !!> `HTTP_PATCH`. If any other value is provided, an **error will be thrown**. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handler. integer , intent ( in ) :: method !! Specifies the HTTP `method` to use. type ( response_type ), intent ( out ) :: response !! The HTTP `response` from the server. integer :: status !! The `status` of setting HTTP method. select case ( method ) case ( 1 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'GET' ) response % method = 'GET' case ( 2 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'HEAD' ) response % method = 'HEAD' case ( 3 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'POST' ) response % method = 'POST' case ( 4 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PUT' ) response % method = 'PUT' case ( 5 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'DELETE' ) response % method = 'DELETE' case ( 6 ) status = curl_easy_setopt ( curl_ptr , CURLOPT_CUSTOMREQUEST , 'PATCH' ) response % method = 'PATCH' case default error stop 'Method argument can be either HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_PATCH' end select end function set_method function set_timeout ( curl_ptr , timeout ) result ( status ) !!> This function sets the `timeout` value **(in seconds)**. !!> !!> If the `timeout` value is **less than zero**, it is ignored and a success status is returned. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. integer ( kind = int64 ), intent ( in ) :: timeout !! `Timeout` seconds for request. integer :: status !! `Status code` indicating whether the operation was successful. if ( timeout < 0 ) then status = 0 else ! setting the maximum time allowed for the connection to established.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_CONNECTTIMEOUT , timeout ) ! setting maximum time allowed for transfer operation.(in seconds) status = curl_easy_setopt ( curl_ptr , CURLOPT_TIMEOUT , timeout ) end if end function set_timeout ! This function determines the type of data to include in the `request body` ! based on the inputs provided. ! If `data` member is provided, it is sent as the body of the ! request. If along with `data` member `file` or `form` or both `file` and `form` members ! are provided then both `form` and `file` member will be ignored and only `data` member will be ! sent in request body. `data` argument takes the highest priority. ! If only `file` member is provided then `file` is sent as the body of the request. and ! a default `Content-type` header with value `multipart/form-data` will be set, if no `Content-type` ! header is provided. If both `form` and `file` members are provided, then `file` ! and the `form` is sent as part of the body. having default `Content-type` header with value `multipart/form-data` ! if no `Content-type` header is provided. ! If data, form, and file are all provided, only data is sent and the form and file ! inputs are ignored. ! ! If only `form` member is provided then `form` data is URL encoded and sent ! as the body of the request. and a default `Content-type` header with value ! `application/x-www-form-urlencoded` will be set, if no `Content-type` header is ! provided ! ! ! data -> data ! form -> form ! file -> file ! data + form + file -> data ! form + file -> form + file (in multipart/form-data) ! ! Note : At a time only one file can be send function set_body ( curl_ptr , request ) result ( status ) !!> The function sets the request `body`. !!____ !!> This function determines and set the type of data to include in the `request body` !!> based on the inputs provided to the `request()` procedure. !!> The function handles different combinations of `data`, `file`, and `form` members !!> to decide the content and the default header for the request body. !!> - If `data` member is provided, it takes the highest priority and is sent as the !!> body of the request. Any other provided `file` or `form` members will be ignored, !!> and only the `data` member will be included in the request body. !!> - If only the `file` member is provided, the `file` is sent as the body of the request. !!> If no `Content-type` header is provided, a default `Content-type` header with value !!> `multipart/form-data` will be set. !!> - If only the `form` member is provided, the `form` data is URL encoded and sent as !!> the body of the request. If no `Content-type` header is provided, a default `Content-type` !!> header with value `application/x-www-form-urlencoded` will be set. !!> - If both `form` and `file` members are provided, both `form` and `file` data are included !!> as part of the request body. A default `Content-type` header with value `multipart/form-data` !!> will be set if no `Content-type` header is provided. !!> - If `data`, `form`, and `file` are all provided, only `data` is sent, and the `form` and `file` !!> inputs are ignored. !!> ### **Combination Behavior Table** !!> | Passed Arguments | Request Body | Default Header | Behavior | !! |--------------------|---------------------------------|-------------------------------|---------------------------------------------------------| !! | data | data | None | The `data` is sent as the body of the request. | !! | file | file | multipart/form-data | The `file` is sent as the body of the request with the default header. | !! | form | Form data URL encoded | application/x-www-form-urlencoded | The `form` data is sent as the body of the request with the default header. | !! | data + file | data (file ignored) | None | The `file` member is ignored, and the `data` is sent as the body of the request. | !! | data + form | data (form ignored) | None | The `form` member is ignored, and the `data` is sent as the body of the request. | !! | file + form | both file and form | multipart/form-data | Both `form` and `file` are sent as part of the request. | !! | data + file + form | data (form and file ignored) | None | Both `form` and `file` members are ignored, and only the `data` is sent as the body of the request. | !!> Note: If custom headers are provided in the `headers` parameter, they will be used. Otherwise, default headers will be applied as mentioned in the table. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the `curl` handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer value representing the status of the function call. integer :: i type ( c_ptr ) :: mime_ptr , part_ptr ! if only data is passed if ( allocated ( request % data )) then status = set_postfields ( curl_ptr , request % data ) ! if file is passsed else if ( allocated ( request % file )) then mime_ptr = curl_mime_init ( curl_ptr ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_filedata ( part_ptr , request % file % value ) status = curl_mime_name ( part_ptr , request % file % name ) ! if both file and form are passed if ( allocated ( request % form )) then do i = 1 , size ( request % form ) part_ptr = curl_mime_addpart ( mime_ptr ) status = curl_mime_data ( part_ptr , request % form ( i )% value , CURL_ZERO_TERMINATED ) status = curl_mime_name ( part_ptr , request % form ( i )% name ) end do end if status = curl_easy_setopt ( curl_ptr , CURLOPT_MIMEPOST , mime_ptr ) ! setting the Content-Type header to multipart/form-data, used for sending binary data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'multipart/form-data' ) end if ! if only form is passed else if ( allocated ( request % form )) then request % form_encoded_str = prepare_form_encoded_str ( curl_ptr , request ) status = set_postfields ( curl_ptr , request % form_encoded_str ) ! setting the Content-Type header to application/x-www-form-urlencoded, used for sending form data if (. not . pair_has_name ( request % header , 'Content-Type' )) then call append_pair ( request % header , 'Content-Type' , 'application/x-www-form-urlencoded' ) end if else ! No curl function was called so set status to zero. status = 0 end if end function set_body function set_postfields ( curl_ptr , data ) result ( status ) !!> Set the data to be sent in the HTTP POST request body. !!____ !!> Use as helper function by `set_body` procedure to set request body type ( c_ptr ), intent ( inout ) :: curl_ptr !! Pointer to the CURL handle. character ( * ), intent ( in ), target :: data !! The data to be sent in the request body. integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDS , c_loc ( data )) status = curl_easy_setopt ( curl_ptr , CURLOPT_POSTFIELDSIZE_LARGE , len ( data , kind = int64 )) end function set_postfields function set_auth ( curl_ptr , request ) result ( status ) !!> Set the user name and password for Authentication. !!_____ !!> It sends the user name and password over the network in plain text, easily captured by others. type ( c_ptr ), intent ( out ) :: curl_ptr !! Pointer to the CURL handle. type ( request_type ), intent ( inout ) :: request !! The HTTP request integer :: status !! An integer indicating whether the operation was successful (0) or not (non-zero). if ( allocated ( request % auth )) then status = curl_easy_setopt ( curl_ptr , CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) status = curl_easy_setopt ( curl_ptr , CURLOPT_USERNAME , request % auth % name ) status = curl_easy_setopt ( curl_ptr , CURLOPT_PASSWORD , request % auth % value ) else ! No curl function was called so set status to zero. status = 0 end if end function set_auth function client_response_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the fortran-curl package to handle HTTP responses. !!> It is called for each `chunk` of data received from the server and appends the data to a !!> `response_type` object. !!>_____ !!> It is called for each `chunk` of data received from the server and appends the data to a `response_type` !!> object passed(i.e `client_data`). The function takes four input arguments: `ptr`, `size`, `nmemb`, !!> and `client_data`. `ptr` is a pointer to the received data buffer, `size` specifies the size of each !!> data element, `nmemb` specifies the number of data elements received, and `client_data` is a pointer to !!> a `response_type` object. The function uses `c_f_pointer` to convert the C pointer to a Fortran pointer and !!> appends the received data to the `content` field of the `response_type` object. The function returns an integer !!> value representing the **number of bytes received.** type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each data element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of data elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Points to a response_type object. integer ( kind = c_size_t ) :: client_response_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf client_response_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) if (. not . allocated ( response % content )) response % content = '' ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return response % content = response % content // buf deallocate ( buf ) response % content_length = response % content_length + nmemb ! Return number of received bytes. client_response_callback = nmemb end function client_response_callback function client_header_callback ( ptr , size , nmemb , client_data ) bind ( c ) !!> This function is a `callback` function used by the `fortran-curl` package to handle HTTP headers. !!>_____ !!> It is called for each header received from the server and stores the header in an `header` member !!> of `response_type` object. type ( c_ptr ), intent ( in ), value :: ptr !! Pointer to the CURL handle. that points to the received header buffer. integer ( kind = c_size_t ), intent ( in ), value :: size !! Specifies the size of each header element. integer ( kind = c_size_t ), intent ( in ), value :: nmemb !! Specifies the number of header elements received. type ( c_ptr ), intent ( in ), value :: client_data !! Pointer to a `response_type` object. integer ( kind = c_size_t ) :: client_header_callback !! The number of bytes received. type ( response_type ), pointer :: response character ( len = :), allocatable :: buf , h_name , h_value integer :: i client_header_callback = int ( 0 , kind = c_size_t ) ! Are the passed C pointers associated? if (. not . c_associated ( ptr )) return if (. not . c_associated ( client_data )) return ! Convert C pointer to Fortran pointer. call c_f_pointer ( client_data , response ) ! Convert C pointer to Fortran allocatable character. call c_f_str_ptr ( ptr , buf , nmemb ) if (. not . allocated ( buf )) return ! Parsing Header, and storing in array of pair_type object i = index ( buf , ':' ) if ( i /= 0 . and . len ( buf ) > 2 ) then h_name = trim ( buf (: i - 1 )) h_value = buf ( i + 2 : ) h_value = h_value ( : len ( h_value ) - 2 ) if ( len ( h_value ) > 0 . and . len ( h_name ) > 0 ) then call append_pair ( response % header , h_name , h_value ) ! response%header = [response%header, pair_type(h_name, h_value)] end if end if deallocate ( buf ) ! Return number of received bytes. client_header_callback = nmemb end function client_header_callback end module http_client","tags":"","loc":"sourcefile/http_client.f90.html"},{"title":"http_request.f90 – HTTP","text":"This file defines the request_type derived type, which \nrepresents an HTTP request . Contents Modules http_request Source Code http_request.f90 Source Code !!> This file defines the **`request_type`** derived type, which !!> represents an **HTTP request**. module http_request !!> This module defines the **`request_type`** derived type, which !!> represents an **HTTP request**. use iso_fortran_env , only : int64 use http_pair , only : pair_type use stdlib_string_type , only : string_type , to_lower , operator ( == ), char implicit none private public :: HTTP_DELETE , HTTP_GET , HTTP_HEAD , HTTP_PATCH , HTTP_POST , HTTP_PUT public :: request_type ! HTTP methods: integer , parameter :: HTTP_GET = 1 integer , parameter :: HTTP_HEAD = 2 integer , parameter :: HTTP_POST = 3 integer , parameter :: HTTP_PUT = 4 integer , parameter :: HTTP_DELETE = 5 integer , parameter :: HTTP_PATCH = 6 ! Request Type type :: request_type !! Representing an **HTTP `request`**. character ( len = :), allocatable :: url !! The URL of the request character ( len = :), allocatable :: data !! The data to be send with request character ( len = :), allocatable :: form_encoded_str !! The URL-encoded form data. integer :: method !! The HTTP method of the request. type ( pair_type ), allocatable :: header (:) !! An Array of request headers. type ( pair_type ), allocatable :: form (:) !! An array of fields in an HTTP form. type ( pair_type ), allocatable :: file !! Used to store information about files to be sent in HTTP requests. integer ( kind = int64 ) :: timeout !! **`Timeout`** value for the request in **seconds**. type ( pair_type ), allocatable :: auth !! Stores the username and password for Authentication end type request_type end module http_request","tags":"","loc":"sourcefile/http_request.f90.html"}]}
\ No newline at end of file
diff --git a/type/client_type.html b/type/client_type.html
index 3664a36..ea27d7f 100644
--- a/type/client_type.html
+++ b/type/client_type.html
@@ -456,7 +456,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/type/pair_type.html b/type/pair_type.html
index 5ea9b3b..d40e938 100644
--- a/type/pair_type.html
+++ b/type/pair_type.html
@@ -354,7 +354,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/type/request_type.html b/type/request_type.html
index e1f8d84..3a2ae40 100644
--- a/type/request_type.html
+++ b/type/request_type.html
@@ -133,15 +133,15 @@
@@ -191,15 +191,15 @@
@@ -246,7 +246,7 @@ Components
-
+
character(len=:),
|
public, |
@@ -263,7 +263,7 @@ Components
-
+
character(len=:),
|
public, |
@@ -280,7 +280,7 @@ Components
-
+
character(len=:),
|
public, |
@@ -297,7 +297,7 @@ Components
-
+
integer,
|
public |
@@ -314,7 +314,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -331,7 +331,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -348,7 +348,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -365,7 +365,7 @@ Components
-
+
integer(kind=int64),
|
public |
@@ -382,7 +382,7 @@ Components
-
+
type(pair_type),
|
public, |
@@ -448,7 +448,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35
diff --git a/type/response_type.html b/type/response_type.html
index b3b7d32..94ef918 100644
--- a/type/response_type.html
+++ b/type/response_type.html
@@ -527,7 +527,7 @@ Source Code
Documentation generated by
FORD
- on 2023-09-02 20:28
+ on 2023-09-24 17:35