Skip to content
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

Add response constructors #64

Merged
merged 1 commit into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Webapi/Webapi__Fetch.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type body
type bodyInit
type headers
type headersInit
type responseInit
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if I should add alias the types from the top level or not as it says they are here for compatibility purposes. Let me know if I should remove them 👍

Copy link
Owner

Choose a reason for hiding this comment

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

This is fine. We can re-evaluate these for the eventual rewrite of the bindings.

type response
type request
type requestInit
Expand Down Expand Up @@ -412,13 +413,35 @@ module Request = {
@get external signal: t => signal = "signal"
}

module ResponseInit = {
type t = responseInit

@obj
external make: (
~status: int=?,
~statusText: string=?,
~headers: headersInit=?,
unit,
) => responseInit = ""
let make = (
~status: option<int>=?,
~statusText: option<string>=?,
~headers: option<headersInit>=?,
tom-sherman marked this conversation as resolved.
Show resolved Hide resolved
) => make(~status?, ~statusText?, ~headers?)
}

module Response = {
type t = response

include Body.Impl({
type t = t
})

@new external make: string => t = "Response"
@new external makeWithInit: (string, responseInit) => t = "Response"
@new external makeWithResponse: t => t = "Response"
@new external makeWithResponseInit: (t, responseInit) => t = "Response"

@val external error: unit => t = "error"
@val external redirect: string => t = "redirect"
@val external redirectWithStatus: (string, int) => t = "redirect"
Expand Down
12 changes: 12 additions & 0 deletions src/Webapi/Webapi__Fetch.resi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type body
type bodyInit
type headers
type headersInit
type responseInit
type response
type request
type requestInit
Expand Down Expand Up @@ -201,9 +202,20 @@ module Request: {
@send external text: t => Js.Promise.t<string> = "text"
}

module ResponseInit: {
type t = responseInit

let make: (~status: int=?, ~statusText: string=?, ~headers: headersInit=?, unit) => t
}

module Response: {
type t = response

@new external make: string => t = "Response"
@new external makeWithInit: (string, responseInit) => t = "Response"
@new external makeWithResponse: t => t = "Response"
@new external makeWithResponseInit: (t, responseInit) => t = "Response"

@val external error: unit => t = "error"
@val external redirect: string => t = "redirect"
@val external redirectWithStatus: (string, int /* enum-ish */) => t = "redirect"
Expand Down