You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/jenspots/http-utils-processor-ts/actions/workflows/build-test.yml)
4
+
3
5
Connector Architecture Typescript processors for handling HTTP operations.
6
+
7
+
## Functions
8
+
9
+
### [`httpFetch`](./src/index.ts)
10
+
11
+
Build and execute an HTTP request. Writes the body of the response into a user specified channel.
12
+
13
+
-`url`: endpoint against which a request is made.
14
+
-`writer`: channel into which the resulting data is written.
15
+
-`options`: an optional parameter which may include:
16
+
-`method` the HTTP method to use. (default: `GET`)
17
+
-`headers`: an array of strings to be used as headers in the outgoing request. (default: `[]`)
18
+
-`acceptStatusCodes`: an array of strings which lists all the status codes deemed "successful". These strings contain either integer literals such as `"200"`, or ranges such as `"200-300"`. Note that range "`a-b`" is inclusive `a`, exclusive `b`. (default: `["200-300"]`)
19
+
-`closeOnEnd`: whether to close the writer stream on end. (default: `true`)
20
+
-`timeOutMilliseconds`: maximum time spend waiting for a response before throwing a `HttpFetchError.timeOutError` error. (default: `null`)
21
+
-`auth`: object describing which authentication flow to use, as well as its parameters. See below for more info. (default: `null`)
22
+
-`cron`: specify the interval at which the function should run as a crontab expression. If `null`, the function only executes once before returning. (default: `null`)
23
+
24
+
#### Authentication
25
+
26
+
This package supports some forms of authentication such as HTTP Basic Authentication and the OAuth 2.0 Password Grant. Additional methods may be implemented by extending the abstract [`Auth`](./src/auth/index.ts) class, after which you must define an additional [`AuthConfig`](./src/auth/index.ts) type and extend the [`Auth.from`](./src/auth/index.ts) static method.
27
+
28
+
##### HTTP Basic Authentication
29
+
30
+
A simple flow which includes the base64 encoded username and password in each request.
31
+
32
+
-`type`: must be set to`basic`.
33
+
-`username`: your username as string.
34
+
-`password`: your plaintext password.
35
+
36
+
##### OAuth 2.0 Password Grant
37
+
38
+
Before executing your request, a POST request is sent to the OAuth server in order to obtain a token. The result of which is embedded as a header inside the original request.
39
+
40
+
-`type`: must be set to `oauth2`
41
+
-`endpoint`: the URL of the OAuth 2.0 server.
42
+
-`username`: your username as string.
43
+
-`password`: your plaintext password.
44
+
45
+
Note that your credentials are not send to the server you specified in the `url` option of `httpFetch`, but only to the `endpoint` you specified above.
46
+
47
+
## Errors
48
+
49
+
All errors thrown in `httpFetch` are of the `HttpFetchError` type, as defined in [`./src/error.ts`](./src/error.ts). This class contains a `HttpUtilsErrorType` enum value which reflects the nature of the error.
50
+
51
+
## Tests
52
+
53
+
At the time of writing, tests should be executed using the Bun runtime.
54
+
55
+
```sh
56
+
$ bun run build
57
+
$ bun test
58
+
```
59
+
60
+
Some tests interact with real online servers, and may therefore require credentials. These can be supplied inside a `.env` file at the root of the repository.
61
+
62
+
```shell
63
+
# Requires OAuth 2.0 Password Grant
64
+
RINF_USERNAME=
65
+
RINF_PASSWORD=
66
+
67
+
# Requires HTTP Basic Auth
68
+
WoRMS_USERNAME=
69
+
WoRMS_PASSWORD=
70
+
71
+
# Needs to be `true` in order to execute
72
+
BLUE_BIKE=true
73
+
```
74
+
75
+
Additional information can be found [here](./tests/README.md).
0 commit comments