Skip to content

Commit 4b8d423

Browse files
committed
feat(http): complete rewrite of the http module to better support all verbs
Deleted the server creation to only focus on queries, as this feels much more important than creating servers using the language. Also adds a lot of long awaited tests. Closes #26, #50, #58
1 parent b8e1058 commit 4b8d423

File tree

14 files changed

+454
-1204
lines changed

14 files changed

+454
-1204
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ jobs:
2020
name: "Ubuntu Clang 16"
2121

2222
steps:
23-
- uses: actions/checkout@v2
24-
if: contains(github.event.head_commit.message, '[skip ci]') == false
23+
- uses: actions/checkout@v4
2524
with:
2625
repository: ArkScript-lang/Ark
2726
path: '.'
@@ -30,7 +29,7 @@ jobs:
3029
- shell: bash
3130
run: rm -r lib/modules
3231

33-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@v4
3433
with:
3534
submodules: recursive
3635
path: lib/modules
@@ -53,6 +52,10 @@ jobs:
5352
shell: bash
5453
run: cmake --build build --config $BUILD_TYPE -j $(nproc)
5554

55+
- uses: actions/setup-python@v5
56+
with:
57+
python-version: '3.13'
58+
5659
- name: Run src module tests
5760
shell: bash
5861
run: ./lib/modules/.github/run-tests src

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Main repository: **[ArkScript](https://github.com/ArkScript-lang/Ark)**
2727

2828
### Network related
2929

30-
* `http` to create http clients and servers
30+
* `http` to make web requests (get, post, put, patch, delete)
3131

3232
## Dependencies
3333

@@ -38,6 +38,6 @@ Main repository: **[ArkScript](https://github.com/ArkScript-lang/Ark)**
3838

3939
## Copyright and Licence information
4040

41-
Copyright (c) 2019-2024 Alexandre Plateau. All rights reserved.
41+
Copyright (c) 2019-2025 Alexandre Plateau. All rights reserved.
4242

4343
This ArkScript distribution contains no GNU GPL code, which means it can be used in proprietary projects.

draft/http/bulk_req.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

draft/http/documentation/README.md

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,103 @@
11
@page http_module HTTP module
22

3-
A module to play with HTTP requests and create web servers, using [cpp-httplib](https://github.com/yhirose/cpp-httplib) (MIT License).
4-
5-
* @subpage http_server
6-
* @subpage http_client
3+
A module to play with HTTP requests, using [cpp-httplib](https://github.com/yhirose/cpp-httplib) (MIT License).
74

85
Disclaimer: this module does not handle
96
* multipart/form-data POST requests
107
* content received with content receiver
118
* content sent with content receiver
129
* chunked transfer encoding
13-
* server-sent events
14-
* multiple servers per program
1510
* digest authentication (needs OpenSSL and libcrypto for that)
11+
12+
## http:headers
13+
14+
Create a header map to use with the http client.
15+
16+
**Parameters**
17+
They work as pairs with:
18+
- `name`: string
19+
- `value`: string
20+
21+
**Return value** `UserType<httpHeaders>`
22+
23+
**Author**
24+
- [@SuperFola](https://github.com/SuperFola)
25+
26+
**Example**
27+
~~~~{.lisp}
28+
(let headers (http:headers
29+
# pair 0
30+
"Accept-Encoding" "gzip, deflate"
31+
# pair 1
32+
"Content-Type" "application/json"))
33+
~~~~
34+
35+
## http:client
36+
37+
Create a http client to query a server.
38+
39+
**Parameters**
40+
- `host`: string, you must not put the protocol `http://` nor `https://`
41+
- `port`: number
42+
43+
**Return value** `List` if the request succeeded: `[status, body]`, otherwise `nil`
44+
45+
**Author**
46+
- [@SuperFola](https://github.com/SuperFola)
47+
48+
**Example**
49+
~~~~{.lisp}
50+
(let cli (http:client "localhost" 1234))
51+
~~~~
52+
53+
## http:get
54+
55+
Get content from an online resource.
56+
57+
**Parameters**
58+
- `client`: `UserType<httpClient>`
59+
- `route`: string
60+
- `headers`: `UserType<httpHeaders>`, optional, always come last
61+
62+
**Return value** `List` if the request succeeded: `[status, body]`, otherwise `nil`
63+
64+
**Author**
65+
- [@SuperFola](https://github.com/SuperFola)
66+
67+
**Example**
68+
~~~~{.lisp}
69+
(let headers (http:headers:create
70+
"Accept-Encoding" "gzip, deflate"))
71+
(let cli (http:client "localhost" 1234))
72+
73+
(mut output (http:get cli "/hi" headers))
74+
(if (nil? output)
75+
(print "couldn't reach the server")
76+
(print (@ output 0))) # print the status
77+
~~~~
78+
79+
## http:post, http:put, http:patch, http:delete
80+
81+
Make a POST / PUT / PATCH / DELETE request with a String as the request's body.
82+
83+
**Parameters**
84+
- `client`: `UserType<httpClient>`
85+
- `route`: string
86+
- `body`: string (request body)
87+
- `mimetype`: string, optional (defaults to `text/plain`)
88+
- `headers`: `UserType<httpHeaders>`, optional, always come last
89+
90+
**Return value** `List` if the request succeeded: `[status, body]`, otherwise `nil`
91+
92+
**Author**
93+
- [@SuperFola](https://github.com/SuperFola)
94+
95+
**Example**
96+
~~~~{.lisp}
97+
(let cli (http:client "localhost" 1234))
98+
99+
(mut output (http:post cli "/hi" "{\"key\": 5}" "application/json" headers))
100+
(if (nil? output)
101+
(print "couldn't reach the server")
102+
(print (@ output 0))) # print the status
103+
~~~~

0 commit comments

Comments
 (0)