-
-
Notifications
You must be signed in to change notification settings - Fork 12
Implement RequestInit via FetchOptions #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Does not fully implement RequestInit, only what seemed useful. Closes: gleam-lang#4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! Thank you for this. I'm sure people will find it very useful.
We never use _with
suffixes in Gleam core, so we'll need to adjust this design slightly. Could you adopt the same pattern that the gleam_httpc
library uses please: https://hexdocs.pm/gleam_httpc/gleam/httpc.html
I've left some notes inline with more details.
@@ -0,0 +1,184 @@ | |||
import gleam/dynamic.{type Dynamic} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamic is for data coming from the outside work, for data going to FFI one should use an accurate type.
Removing the dynamic use here will also fix the warnings that dynamic.from
emits in current gleam_stdlib
|> fetch_options.set_credentials(fetch_options.CredentialsOmit) | ||
|> fetch_options.set_keepalive(True) | ||
|> fetch_options.set_priority(fetch_options.High) | ||
|> fetch_options.set_redirect(fetch_options.Follow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this test verify? Doesn't seem like there's assertions for any of these?
} | ||
|
||
export function setKeyFetchOptions(fetchOptions, key, value) { | ||
fetchOptions[key] = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this mutates the configuration! In Gleam all data should be immutable. Copying the gleam_httpc
design and moving the code into Gleam will resolve the problem.
As a rule of thumb FFI code should not be used for basic data manipulation, Gleam is perfectly capable of that.
@@ -0,0 +1,184 @@ | |||
import gleam/dynamic.{type Dynamic} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one module please, no new module for configuration.
@@ -0,0 +1,184 @@ | |||
import gleam/dynamic.{type Dynamic} | |||
|
|||
/// Gleam equivalent of JavaScript [`RequestInit`](https://developer.mozilla.org/docs/Web/API/RequestInit). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap doc comments at 80 lines like regular Gleam code, and included documentation for each option rather solely linking to an external resource 🙏
CredentialsInclude | ||
} | ||
|
||
/// Cors options, for details see [`mode`](https://developer.mozilla.org/docs/Web/API/RequestInit#mode). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Cors options, for details see [`mode`](https://developer.mozilla.org/docs/Web/API/RequestInit#mode). | |
/// CORS options, for details see [`mode`](https://developer.mozilla.org/docs/Web/API/RequestInit#mode). |
Does not fully implement RequestInit, only what seemed useful.
Closes: #4
Deprecates: #5