Skip to content

Commit

Permalink
Merge pull request #64 from tom-sherman/response-constructors
Browse files Browse the repository at this point in the history
Add response constructors
  • Loading branch information
TheSpyder authored Dec 24, 2021
2 parents df77792 + 9c66ad2 commit 7c8e719
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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
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>=?,
) => 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

0 comments on commit 7c8e719

Please sign in to comment.