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 package as the underlying mechanism.
Interface for
new_client
function.
This is the constructor for the
client_type
derived type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(request_type), | intent(in) | :: | request |
Specifies the HTTP |
A client_type
object containing the request
field set to the input request
object.
Interface for
new_request
function.
This function create a
request_type
object and populates it. The function returns theresponse_type
object containing the server's response.
Note :
If the
header
argument is not provided, defaultuser-agent
header is set tohttp-client/0.1
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | url |
Specifies the |
||
integer, | intent(in), | optional | :: | method |
Specifies the HTTP |
|
type(pair_type), | intent(in), | optional | :: | header(:) |
Specifies the request |
|
character(len=*), | intent(in), | optional | :: | data |
Specifies the |
|
type(pair_type), | intent(in), | optional | :: | form(:) |
Specifies the |
|
type(pair_type), | intent(in), | optional | :: | file |
Specifies the |
|
integer, | intent(in), | optional | :: | timeout |
|
|
type(pair_type), | intent(in), | optional | :: | auth |
stores the |
Stores the server's response
.
A derived type, responsible for making actual HTTP request
using
fortran-curl at backend.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(request_type), | public | :: | request |
Interface for new_client
function.
private function new_client (request) | This is the constructor for the |
procedure , public , :: client_get_response Function |
This function create a request_type
object and populates it.
The function returns the response_type
object containing the
server's response.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | url |
Specifies the |
||
integer, | intent(in), | optional | :: | method |
Specifies the HTTP |
|
type(pair_type), | intent(in), | optional | :: | header(:) |
Specifies the request |
|
character(len=*), | intent(in), | optional | :: | data |
Specifies the |
|
type(pair_type), | intent(in), | optional | :: | form(:) |
Specifies the |
|
type(pair_type), | intent(in), | optional | :: | file |
Specifies the |
|
integer, | intent(in), | optional | :: | timeout |
|
|
type(pair_type), | intent(in), | optional | :: | auth |
stores the |
Stores the server's response
.
This is the constructor for the client_type
derived type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(request_type), | intent(in) | :: | request |
Specifies the HTTP |
A client_type
object containing the request
field set to the input request
object.
This function sends an HTTP request
to a server using the
fortran-curl package
and stores the server's response in a response_type
object.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(client_type), | intent(inout) | :: | this |
Contains the HTTP |
Contains the server's response.
This subroutine converts the request%form
into a URL-encoded name-value
string and returns it.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(out) | :: | curl_ptr |
Pointer to the |
||
type(request_type), | intent(inout) | :: | request |
The HTTP |
Stores the URL Encoded string.
This function sets the HTTP method
for the request.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(out) | :: | curl_ptr |
Pointer to the |
||
integer, | intent(in) | :: | method |
Specifies the HTTP |
||
type(response_type), | intent(out) | :: | response |
The HTTP |
The status
of setting HTTP method.
This function sets the timeout
value (in seconds).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(out) | :: | curl_ptr |
Pointer to the |
||
integer(kind=int64), | intent(in) | :: | timeout |
|
Status code
indicating whether the operation was successful.
The function sets the request body
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(out) | :: | curl_ptr |
Pointer to the |
||
type(request_type), | intent(inout) | :: | request |
The HTTP request |
An integer value representing the status of the function call.
Set the data to be sent in the HTTP POST request body.
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. |
An integer indicating whether the operation was successful (0) or not (non-zero).
Set the user name and password for Authentication.
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 |
An integer indicating whether the operation was successful (0) or not (non-zero).
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.
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. |
The number of bytes received.
This function is a callback
function used by the fortran-curl
package to handle HTTP headers.
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 |
The number of bytes received.
This subroutine prepares headers
in required format(Linked list) for an HTTP request.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(out) | :: | header_list_ptr |
A |
||
type(pair_type), | intent(in), | allocatable | :: | req_headers(:) |
The |