The http Fortran package provides a simple and convenient way to make HTTP requests and retrieve responses. It aims to simplify the process of interacting with web services by providing a high-level API.
Find us on…
http-client is Fortran library to make HTTP requests. It simplifies interacting with web services by providing a high-level and user-friendly interface.
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.Before building the http-client library, ensure that you have the necessary dependencies installed. On Ubuntu, you need to install the curl development headers. 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 your the fpm.toml file of your package:
[dependencies]
http = { git = "https://github.com/fortran-lang/http-client.git" }
stdlib = "*"
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
Response Length : 83
Response Method : GET
Response Content : {
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
In this example, we make a GET
request to the URL
https://jsonplaceholder.typicode.com/todos/1 to retrieve JSON data.
If the request is successful, we print the response code, content length,
method, and content. If the request fails, we print the error message.
To begin your journey with our package, dive into the comprehensive tutorial available here: tutorial.md.
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 (PR) and adding your project details.
Thank you for your interest in http-client! Contributions from the community are esential for improving the package. This section provides a guide on how to get the code, build the library, and run examples and tests.
To get started, follow these steps:
Clone the repository using Git:
git clone https://github.com/fortran-lang/http-client
cd http-client
Before building the library, ensure that you have the necessary dependencies installed. On Ubuntu, you need to install the curl development headers. Use the following command:
sudo apt install -y libcurl4-openssl-dev
http-client uses fpm as the build system. Make sure you have fpm-0.8.x or later installed. To build the library, run the following command within the project directory:
fpm build
http-client provides example programs that demonstrate its use. To run the examples, use the following command:
fpm run --example <example name>
Executing this command will execute the example programs, allowing you to see the package in action and understand how to utilize its features.
http-client includes a test suite to ensure its functionality is working as expected. To run the tests, type:
fpm test
Running the tests will validate the behavior of the package and help identify any issues or regressions.
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
http-client is known to work with the following compilers:
When contributing to the http Fortran package, please keep the following guidelines in mind:
We appreciate your contributions and look forward to your valuable input in improving http-client.
Happy coding!👋