Skip to content

Conversation

duzda
Copy link
Contributor

@duzda duzda commented Aug 31, 2025

Does not fully implement RequestInit, only what seemed useful.

Closes: #4
Deprecates: #5

Does not fully implement RequestInit, only what seemed useful.

Closes: gleam-lang#4
@duzda
Copy link
Contributor Author

duzda commented Sep 4, 2025

Hi @lpil, just to let you know, I will open the PR for the second part of #19 once this one gets merged, as it depends directly on this one

Copy link
Member

@lpil lpil left a 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}
Copy link
Member

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)
Copy link
Member

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;
Copy link
Member

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}

Copy link
Member

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).
Copy link
Member

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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).

@lpil lpil marked this pull request as draft September 7, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing options when sending fetch requests
2 participants