Skip to content

Commit e9f4926

Browse files
Add Complete Tutorials (#53)
* Add Complete Tutorials * Rename the tutorial file and Update the loop to iterate through all repositories. * Update the version of fortran-curl * removed TOC from README.md * Clean up README --------- Co-authored-by: milancurcic <[email protected]>
1 parent dfd4812 commit e9f4926

File tree

6 files changed

+952
-106
lines changed

6 files changed

+952
-106
lines changed

README.md

Lines changed: 114 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
1-
# **http**
2-
## **Overview**
3-
4-
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.
5-
6-
___
7-
## **Features**
8-
9-
The package includes the following features:
10-
11-
1. #### **Sending HTTP Requests:**
12-
- **`GET`**: Retrieve data from the server.
13-
- **`POST`**: Submit data to be processed by the server.
14-
- **`PUT`**: Replace or create resources on the server.
15-
- **`DELETE`**: Remove resources from the server.
16-
- **`PATCH`**: Partial updates to resources.
17-
- **`HEAD`**: Retrieve response headers without the response content.
18-
19-
2. #### **Data Support:**
20-
- Send any type of data with requests, including support for `file` uploads and `form data`.
21-
22-
3. #### **Response Handling:**
23-
- Retrieve response `content`.
24-
- Get the HTTP `status code` returned by the server.
25-
- Fetch the `length` of the response content.
26-
- Access response `headers`.
27-
28-
4. #### **Custom Headers:**
29-
- Include `custom headers` in requests to the server.
30-
31-
5. #### **Error Handling:**
32-
- Detect and handle unsuccessful requests gracefully, with informative `error messages`.
33-
34-
6. #### **Request Timeout:**
35-
- Set a maximum time allowed for a request to complete, improving responsiveness.
36-
37-
7. #### **Authentication:**
38-
- Authenticate requests to protected resources using standard authentication methods.
39-
40-
## **Installation**
41-
42-
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:
1+
# http-client
2+
3+
http-client is Fortran library to make HTTP requests.
4+
It simplifies interacting with web services by providing a high-level and
5+
user-friendly interface.
6+
7+
## Features
8+
9+
* HTTP request methods:
10+
- `GET`: Retrieve data from the server.
11+
- `POST`: Create new data the server.
12+
- `PUT`: Replace an existing resource on the server.
13+
- `DELETE`: Delete a resource from the server.
14+
- `PATCH`: Partially update a resource on the server.
15+
- `HEAD`: Get response headers without the response content.
16+
* Supported data types:
17+
- URL encoded fields
18+
- HTTP form data
19+
- File uploads
20+
* Response handling:
21+
- Retrieve response body (content).
22+
- Get the HTTP status code returned by the server.
23+
- Access response headers.
24+
* Setting custom request headers
25+
* Error handling with informative error messages
26+
* Setting request timeouts
27+
* Basic HTTP authentication
28+
29+
## Installation
30+
31+
Before building the http-client library, ensure that you have the necessary
32+
dependencies installed. On Ubuntu, you need to install the curl development
33+
headers. Use the following command:
4334

4435
```
4536
sudo apt install -y libcurl4-openssl-dev
4637
```
4738

48-
To use `http-client` within your fpm project, add the following to your package `fpm.toml` file:
39+
To use http-client as a dependency in your fpm project, add the following to
40+
your the fpm.toml file of your package:
4941

5042
```toml
5143
[dependencies]
5244
http = { git = "https://github.com/fortran-lang/http-client.git" }
5345
stdlib = "*"
5446
```
55-
## **Usage Example**
56-
The following example demonstrates how to use the http package to make a **Simple GET request** and process the response
47+
48+
## Example use
49+
50+
The following example demonstrates how to use http-client to make a simple `GET`
51+
request and process the response:
5752

5853
```fortran
5954
program simple_get
@@ -78,7 +73,9 @@ program simple_get
7873
end program simple_get
7974
8075
```
81-
### Ouptut :
76+
77+
Ouptut:
78+
8279
```
8380
Response Code : 200
8481
Response Length : 83
@@ -90,100 +87,114 @@ end program simple_get
9087
"completed": false
9188
}
9289
```
93-
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***.
94-
95-
## **Getting Started Guides**
96-
> ### ***The Complete Tutorial Guide is <u> Currently in progress</u> and will be available soon.***
97-
1. ### **Installation** 👋
98-
- Installing Dependencies (Ubuntu)
99-
- Setting up the Package in your Project
100-
101-
2. ### **Making HTTP Requests** 🚀
102-
- **Sending `GET` Requests**
103-
- *Accessing Response `Content`*
104-
- *Retrieving `Status Codes`*
105-
- *Getting Response `Headers`*
106-
- *Extracting `Content Length`*
107-
- **Sending `POST` Requests**
108-
- *Sending `Data` with Requests*
109-
- *Sending `Form Data`*
110-
- *Uploading `File`*
111-
- **Sending `PUT` Requests**
112-
- **Sending `PATCH` Requests**
113-
- **Sending `DELETE` Requests**
114-
- **Sending `HEAD` Requests**
115-
116-
3. ### **Customizing Requests** ✏️
117-
- Sending Custom **Headers**
118-
- Setting Request **Timeout**
119-
- **Authentication** Option
120-
121-
4. ### **Error Handling** 🤨
122-
- Handling Unsuccessful Requests
123-
- Displaying Error Messages
124-
125-
5. ### **Real Projects** 🤖
126-
- **GitHub organization analyzer** : Retrieve valuable information about the organization repositories
127-
128-
129-
## **Contributing to project**
130-
Thank you for your interest in contributing to the `http` Fortran package! Contributions from the community are valuable in improving and enhancing the functionality of the package. This section provides a guide on how to get the code, build the library, and run examples and tests.
131-
132-
### **Get the code**
90+
91+
In this example, we make a `GET` request to the URL
92+
https://jsonplaceholder.typicode.com/todos/1 to retrieve JSON data.
93+
If the request is successful, we print the response code, content length,
94+
method, and content. If the request fails, we print the error message.
95+
96+
## Getting Started Guides
97+
98+
To begin your journey with our package, dive into the comprehensive tutorial
99+
available here: [tutorial.md](./tutorial/tutorial.md)**.
100+
101+
## Projects using http-client
102+
103+
* [github-org-analyzer](https://github.com/rajkumardongre/github-org-analyzer):
104+
An example mini-project to demonstrate the use of http-client by downloading
105+
and parsing data from the GitHub API.
106+
* [fortran-xkcd](https://github.com/rajkumardongre/fortran-xkcd/tree/http_client_version):
107+
An fpm example project that displays the latest xkcd comic inside an X window.
108+
As a limitation, only images in PNG format are supported.
109+
The alt text will be printed to console.
110+
* [foropenai](https://github.com/gha3mi/foropenai): A Fortran library to access
111+
* the OpenAI API.
112+
113+
If you're using http-client in your Fortran project and would like to be
114+
included on this list, we welcome you to contribute by creating a pull request
115+
(PR) and adding your project details.
116+
117+
## Contributing to project
118+
119+
Thank you for your interest in http-client! Contributions from the community
120+
are esential for improving the package. This section provides a guide on how to
121+
get the code, build the library, and run examples and tests.
122+
123+
### Get the code
124+
133125
To get started, follow these steps:
134126

135127
Clone the repository using Git:
128+
136129
```
137130
git clone https://github.com/fortran-lang/http-client
138131
cd http-client
139132
```
140-
### **Prerequisites**
141-
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:
133+
134+
### Prerequisites
135+
136+
Before building the library, ensure that you have the necessary dependencies
137+
installed. On Ubuntu, you need to install the curl development headers.
138+
Use the following command:
139+
142140
```
143141
sudo apt install -y libcurl4-openssl-dev
144142
```
145-
### **Build the library**
146143

147-
The `http` package uses **fpm** as the build system. Make sure you have fpm `version 0.8.x` or later installed. To build the library, execute the following command within the project directory:
144+
### Build the library
145+
146+
http-client uses **fpm** as the build system. Make sure you have fpm-0.8.x or
147+
later installed. To build the library, run the following command within the
148+
project directory:
149+
148150

149151
```
150152
fpm build
151153
```
152-
### **Run examples**
153-
The http package provides example programs that demonstrate its usage. To run the examples, use the following command:
154+
155+
### Run examples
156+
157+
http-client provides example programs that demonstrate its use. To run the
158+
examples, use the following command:
154159

155160
```
156161
fpm run --example <example name>
157162
```
158-
Executing this command will execute the example programs, allowing you to see the package in action and understand how to utilize its features.
159163

160-
### **Run tests**
161-
The http package includes a test suite to ensure its functionality is working as expected. To run the tests, execute the following command:
164+
Executing this command will execute the example programs, allowing you to see
165+
the package in action and understand how to utilize its features.
166+
167+
### Run tests
168+
169+
http-client includes a test suite to ensure its functionality is working as
170+
expected. To run the tests, type:
171+
162172
```
163173
fpm test
164174
```
165-
Running the tests will validate the behavior of the package and help identify any issues or regressions.
166175

167-
### **Generating API Documentation**
176+
Running the tests will validate the behavior of the package and help identify
177+
any issues or regressions.
168178

169-
Before generating API documentation, ensure that you have FORD installed on your system.
179+
### Generating API Documentation
170180

171-
**Installation link**: [https://github.com/Fortran-FOSS-Programmers/ford#installation](https://github.com/Fortran-FOSS-Programmers/ford#installation)
181+
Before generating API documentation, ensure that you have FORD
182+
[installed on your system](https://github.com/Fortran-FOSS-Programmers/ford#installation).
172183

173184
Once FORD is set up, execute the following command to build the API documentation:
174185

175186
```bash
176187
ford ford.md
177188
```
178189

179-
### **Supported compilers**
190+
### Supported compilers
180191

181192
http-client is known to work with the following compilers:
182193

183194
* GFortran 11 & 12 (tested in CI)
184195
* Intel OneAPI ifx v2023.1.0 and ifort classic v2021.9.0
185196

186-
### **Contributing guidelines**
197+
### Contributing guidelines
187198

188199
When contributing to the http Fortran package, please keep the following guidelines in mind:
189200

@@ -194,6 +205,6 @@ When contributing to the http Fortran package, please keep the following guideli
194205
* Make sure to test your changes and ensure they do not introduce regressions or break existing functionality.
195206
* Submit a pull request with your changes, providing a clear explanation of the problem you are solving and the approach you have taken.
196207

197-
We appreciate your contributions and look forward to your valuable input in improving the http Fortran package.
208+
We appreciate your contributions and look forward to your valuable input in improving http-client.
198209

199-
Happy coding!
210+
Happy coding!👋

fpm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ implicit-external = false
1919
source-form = "free"
2020

2121
[dependencies]
22-
fortran-curl = {git = "https://github.com/interkosmos/fortran-curl.git"}
22+
fortran-curl = {git = "https://github.com/interkosmos/fortran-curl.git", tag = "0.5.0"}
2323
stdlib = "*"

src/http/http_request.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module http_request
4343
type(pair_type), allocatable :: file
4444
!! Used to store information about files to be sent in HTTP requests.
4545
integer(kind=int64) :: timeout
46+
!! **`Timeout`** value for the request in **seconds**.
4647
type(pair_type), allocatable :: auth
4748
!! Stores the username and password for Authentication
4849
end type request_type

test/test_get.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ program test_get
2222
pair_type('Set-Cookie', 'Theme-Light'), &
2323
pair_type('Set-Cookie', 'Auth-Token: 12345'), &
2424
pair_type('User-Agent', 'my user agent') &
25-
]
25+
]
2626

27-
! res = request(url='https://reqres.in/api/users/1', header=request_header)
2827
res = request(url='https://dummyjson.com/products/1', header=request_header)
2928

3029
msg = 'test_get: '

0 commit comments

Comments
 (0)