git.iko.soy/rowtype-yoga/purescript-fetch-core
on main help sign in
Initial commit
commit375baae53e4af31ab9b9f3f246a602a82fd704c4 authorNathan Faubion <nathan@awakesecurity.com> dateTue 14 Jan 2020, 11:12 (7 years ago)
23 files changed+646
.gitignore+9 LICENSE+21 README.md+1 bower.json+28 src/Web/Fetch.js+1 src/Web/Fetch.purs+26 src/Web/Fetch/AbortController.js+13 src/Web/Fetch/AbortController.purs+14 src/Web/Fetch/Headers.js+23 src/Web/Fetch/Headers.purs+53 src/Web/Fetch/Integrity.purs+10 src/Web/Fetch/Referrer.purs+18 src/Web/Fetch/ReferrerPolicy.purs+36 src/Web/Fetch/Request.js+8 src/Web/Fetch/Request.purs+191 src/Web/Fetch/RequestBody.js+5 src/Web/Fetch/RequestBody.purs+16 src/Web/Fetch/RequestCache.purs+30 src/Web/Fetch/RequestCredentials.purs+21 src/Web/Fetch/RequestMode.purs+24 src/Web/Fetch/RequestRedirect.purs+21 src/Web/Fetch/Response.js+47 src/Web/Fetch/Response.purs+30
.gitignorenew file+9
@@ -0,0 +1,9 @@
1+/bower_components/
2+/node_modules/
3+/.pulp-cache/
4+/output/
5+/generated-docs/
6+/.psc-package/
7+/.psc*
8+/.purs*
9+/.psa*
LICENSEnew file+21
@@ -0,0 +1,21 @@
1+MIT License
2+
3+Copyright (c) 2020 Awake Security
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+
12+The above copyright notice and this permission notice shall be included in all
13+copies or substantial portions of the Software.
14+
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+SOFTWARE.
README.mdnew file+1
@@ -0,0 +1 @@
1+# purescript-web-fetch
bower.jsonnew file+28
@@ -0,0 +1,28 @@
1+{
2+ "name": "purescript-web-fetch",
3+ "homepage": "https://github.com/purescript-web/purescript-web-fetch",
4+ "license": "MIT",
5+ "repository": {
6+ "type": "git",
7+ "url": "git://github.com/purescript-web/purescript-web-fetch.git"
8+ },
9+ "ignore": [
10+ "**/.*",
11+ "bower_components",
12+ "node_modules",
13+ "output",
14+ "bower.json",
15+ "package.json"
16+ ],
17+ "dependencies": {
18+ "purescript-prelude": "^4.0.0",
19+ "purescript-effect": "^2.0.0",
20+ "purescript-http-methods": "^4.0.0",
21+ "purescript-typelevel-prelude": "^5.0.0",
22+ "purescript-web-file": "^2.3.0",
23+ "purescript-record": "^2.0.0",
24+ "purescript-foreign-object": "^2.0.0",
25+ "purescript-web-promise": "https://github.com/purescript-web/purescript-web-promise.git#^1.0.0",
26+ "purescript-web-streams": "https://github.com/purescript-web/purescript-web-streams.git#^1.0.0"
27+ }
28+}
src/Web/Fetch.jsnew file+1
@@ -0,0 +1 @@
1+exports._fetch = fetch;
src/Web/Fetch.pursnew file+26
@@ -0,0 +1,26 @@
1+module Web.Fetch
2+ ( FetchOptions
3+ , fetch
4+ , fetchWithOptions
5+ ) where
6+
7+import Effect (Effect)
8+import Effect.Uncurried (EffectFn2, runEffectFn2)
9+import Prim.Row as Row
10+import Web.Fetch.AbortController (AbortSignal)
11+import Web.Fetch.Request (Request)
12+import Web.Fetch.Response (Response)
13+import Web.Promise (Promise)
14+
15+type FetchOptions =
16+ ( keepalive :: Boolean
17+ , signal :: AbortSignal
18+ )
19+
20+foreign import _fetch :: forall r. EffectFn2 Request { | r } (Promise Response)
21+
22+fetch :: Request -> Effect (Promise Response)
23+fetch req = runEffectFn2 _fetch req {}
24+
25+fetchWithOptions :: forall r rx. Row.Union r rx FetchOptions => Request -> { | r } -> Effect (Promise Response)
26+fetchWithOptions = runEffectFn2 _fetch
src/Web/Fetch/AbortController.jsnew file+13
@@ -0,0 +1,13 @@
1+exports.new = function() {
2+ return new AbortController();
3+};
4+
5+exports.abort = function(controller) {
6+ return function() {
7+ return controller.abort();
8+ };
9+};
10+
11+exports.signal = function(controller) {
12+ return controller.signal;
13+};
src/Web/Fetch/AbortController.pursnew file+14
@@ -0,0 +1,14 @@
1+module Web.Fetch.AbortController where
2+
3+import Effect (Effect)
4+import Prelude (Unit)
5+
6+foreign import data AbortController :: Type
7+
8+foreign import data AbortSignal :: Type
9+
10+foreign import new :: Effect AbortController
11+
12+foreign import abort :: AbortController -> Effect Unit
13+
14+foreign import signal :: AbortController -> AbortSignal
src/Web/Fetch/Headers.jsnew file+23
@@ -0,0 +1,23 @@
1+exports.unsafeNew = function() {
2+ return new Headers();
3+};
4+
5+exports.unsafeAppend = function(key, value, headers) {
6+ return headers.append(key, value);
7+};
8+
9+exports.unsafeFromRecord = function(r) {
10+ return new Headers(r);
11+};
12+
13+exports._toArray = function(tuple, headers) {
14+ var arr = [];
15+ for (var pair of headers.entries()) {
16+ arr.push(tuple(pair[0])(pair[1]));
17+ }
18+ return arr;
19+}
20+
21+exports.fromObject = function(obj) {
22+ return new Headers(obj);
23+};
src/Web/Fetch/Headers.pursnew file+53
@@ -0,0 +1,53 @@
1+module Web.Fetch.Headers
2+ ( Headers
3+ , fromFoldable
4+ , fromRecord
5+ , fromObject
6+ , toArray
7+ , toUnfoldable
8+ , empty
9+ ) where
10+
11+import Prelude
12+
13+import Data.Array as Array
14+import Data.Foldable (class Foldable, foldM)
15+import Data.Function.Uncurried (Fn2, runFn2)
16+import Data.Tuple (Tuple(..))
17+import Data.Unfoldable (class Unfoldable)
18+import Effect (Effect)
19+import Effect.Uncurried (EffectFn3, runEffectFn3)
20+import Effect.Unsafe (unsafePerformEffect)
21+import Foreign.Object (Object)
22+import Type.Row.Homogeneous (class Homogeneous)
23+
24+foreign import data Headers :: Type
25+
26+foreign import unsafeNew :: Effect Headers
27+
28+foreign import unsafeAppend :: EffectFn3 String String Headers Unit
29+
30+foreign import unsafeFromRecord :: forall r. { | r } -> Headers
31+
32+foreign import _toArray :: Fn2 (forall a b. a -> b -> Tuple a b) Headers (Array (Tuple String String))
33+
34+foreign import fromObject :: Object String -> Headers
35+
36+fromFoldable :: forall f. Foldable f => f (Tuple String String) -> Headers
37+fromFoldable f = unsafePerformEffect do
38+ init <- unsafeNew
39+ foldM (\headers (Tuple key value) -> do
40+ runEffectFn3 unsafeAppend key value headers
41+ pure headers) init f
42+
43+fromRecord :: forall r. Homogeneous r String => { | r } -> Headers
44+fromRecord = unsafeFromRecord
45+
46+toArray :: Headers -> Array (Tuple String String)
47+toArray = runFn2 _toArray Tuple
48+
49+toUnfoldable :: forall f. Unfoldable f => Headers -> f (Tuple String String)
50+toUnfoldable = Array.toUnfoldable <<< toArray
51+
52+empty :: Headers
53+empty = fromFoldable []
src/Web/Fetch/Integrity.pursnew file+10
@@ -0,0 +1,10 @@
1+module Web.Fetch.Integrity where
2+
3+import Data.Newtype (class Newtype)
4+import Prelude (class Eq, class Ord)
5+
6+newtype Integrity = Integrity String
7+
8+derive instance newtypeIntegrity :: Newtype Integrity _
9+derive newtype instance eqIntegrity :: Eq Integrity
10+derive newtype instance ordIntegrity :: Ord Integrity
src/Web/Fetch/Referrer.pursnew file+18
@@ -0,0 +1,18 @@
1+module Web.Fetch.Referrer where
2+
3+data Referrer
4+ = ReferrerNone
5+ | ReferrerClient
6+ | ReferrerUrl String
7+
8+toString :: Referrer -> String
9+toString = case _ of
10+ ReferrerNone -> "none"
11+ ReferrerClient -> "client"
12+ ReferrerUrl url -> url
13+
14+fromString :: String -> Referrer
15+fromString = case _ of
16+ "none" -> ReferrerNone
17+ "client" -> ReferrerClient
18+ url -> ReferrerUrl url
src/Web/Fetch/ReferrerPolicy.pursnew file+36
@@ -0,0 +1,36 @@
1+module Web.Fetch.ReferrerPolicy where
2+
3+import Data.Maybe (Maybe(..))
4+
5+data ReferrerPolicy
6+ = Default
7+ | NoReferrer
8+ | NoReferrerWhenDowngrade
9+ | SameOrigin
10+ | StrictOrigin
11+ | OriginWhenCrossOrigin
12+ | StrictOriginWhenCrossOrigin
13+ | UnsafeUrl
14+
15+toString :: ReferrerPolicy -> String
16+toString = case _ of
17+ Default -> ""
18+ NoReferrer -> "no-referrer"
19+ NoReferrerWhenDowngrade -> "no-referrer-when-downgrade"
20+ SameOrigin -> "same-origin"
21+ StrictOrigin -> "strict-origin"
22+ OriginWhenCrossOrigin -> "origin-when-cross-origin"
23+ StrictOriginWhenCrossOrigin -> "strict-origin-when-cross-origin"
24+ UnsafeUrl -> "unsafe-url"
25+
26+fromString :: String -> Maybe ReferrerPolicy
27+fromString = case _ of
28+ "" -> Just Default
29+ "no-referrer" -> Just NoReferrer
30+ "no-referrer-when-downgrade" -> Just NoReferrerWhenDowngrade
31+ "same-origin" -> Just SameOrigin
32+ "strict-origin" -> Just StrictOrigin
33+ "origin-when-cross-origin" -> Just OriginWhenCrossOrigin
34+ "strict-origin-when-cross-origin" -> Just StrictOriginWhenCrossOrigin
35+ "unsafe-url" -> Just UnsafeUrl
36+ _ -> Nothing
src/Web/Fetch/Request.jsnew file+8
@@ -0,0 +1,8 @@
1+exports._unsafeNew = function(url, options) {
2+ try {
3+ return new Request(url, options);
4+ } catch (e) {
5+ console.error(e);
6+ throw e;
7+ }
8+};
src/Web/Fetch/Request.pursnew file+191
@@ -0,0 +1,191 @@
1+module Web.Fetch.Request
2+ ( Request
3+ , RequestOptions
4+ , UnsafeRequestOptions
5+ , new
6+ , new'
7+ , unsafeNew
8+ , class BuildRequestOptions
9+ , buildRequestOptions
10+ , defaultOptions
11+ , defaultUnsafeOptions
12+ , class ConvertOptions
13+ , convertOptions
14+ , class ConvertOption
15+ , convertOption
16+ ) where
17+
18+import Prelude
19+
20+import Data.ArrayBuffer.Types (ArrayBuffer, ArrayView)
21+import Data.HTTP.Method (Method(..))
22+import Data.Maybe (Maybe(..))
23+import Data.Newtype (un)
24+import Data.Nullable (Nullable, toNullable)
25+import Data.Symbol (class IsSymbol, SProxy(..))
26+import Data.Tuple (Tuple)
27+import Effect (Effect)
28+import Effect.Uncurried (EffectFn2, runEffectFn2)
29+import Foreign.Object (Object)
30+import Prim.Row as Row
31+import Prim.RowList (kind RowList)
32+import Prim.RowList as RowList
33+import Record (merge)
34+import Record.Builder as Record
35+import Type.Data.RowList (RLProxy(..))
36+import Type.Row.Homogeneous (class Homogeneous)
37+import Web.Fetch.Headers (Headers)
38+import Web.Fetch.Headers as Headers
39+import Web.Fetch.Integrity (Integrity(..))
40+import Web.Fetch.Referrer (Referrer)
41+import Web.Fetch.Referrer as Referrer
42+import Web.Fetch.ReferrerPolicy (ReferrerPolicy)
43+import Web.Fetch.ReferrerPolicy as ReferrerPolicy
44+import Web.Fetch.RequestBody (RequestBody)
45+import Web.Fetch.RequestBody as RequestBody
46+import Web.Fetch.RequestCache (RequestCache)
47+import Web.Fetch.RequestCache as RequestCache
48+import Web.Fetch.RequestCredentials (RequestCredentials)
49+import Web.Fetch.RequestCredentials as RequestCredentials
50+import Web.Fetch.RequestMode (RequestMode)
51+import Web.Fetch.RequestMode as RequestMode
52+
53+foreign import data Request :: Type
54+
55+foreign import _unsafeNew :: forall r. EffectFn2 String { | r } Request
56+
57+type UnsafeRequestOptions =
58+ ( method :: String
59+ , headers :: Headers
60+ , body :: RequestBody
61+ , credentials :: String
62+ , cache :: String
63+ , mode :: String
64+ , referrer :: Nullable String
65+ , referrerPolicy :: String
66+ , integrity :: String
67+ )
68+
69+type RequestOptions =
70+ ( method :: Method
71+ , headers :: Headers
72+ , body :: RequestBody
73+ , credentials :: RequestCredentials
74+ , cache :: RequestCache
75+ , mode :: RequestMode
76+ , referrer :: Maybe Referrer
77+ , referrerPolicy :: ReferrerPolicy
78+ , integrity :: Integrity
79+ )
80+
81+defaultOptions :: { | RequestOptions }
82+defaultOptions =
83+ { method: GET
84+ , headers: Headers.empty
85+ , body: RequestBody.empty
86+ , credentials: RequestCredentials.SameOrigin
87+ , cache: RequestCache.Default
88+ , mode: RequestMode.Cors
89+ , referrer: Nothing
90+ , referrerPolicy: ReferrerPolicy.NoReferrer
91+ , integrity: Integrity ""
92+ }
93+
94+defaultUnsafeOptions :: { | UnsafeRequestOptions }
95+defaultUnsafeOptions = toUnsafeOptions defaultOptions
96+
97+toUnsafeOptions :: { | RequestOptions } -> { | UnsafeRequestOptions }
98+toUnsafeOptions opts =
99+ { method: show opts.method
100+ , headers: opts.headers
101+ , body: opts.body
102+ , credentials: RequestCredentials.toString opts.credentials
103+ , cache: RequestCache.toString opts.cache
104+ , mode: RequestMode.toString opts.mode
105+ , referrer: toNullable $ Referrer.toString <$> opts.referrer
106+ , referrerPolicy: ReferrerPolicy.toString opts.referrerPolicy
107+ , integrity: un Integrity opts.integrity
108+ }
109+
110+unsafeNew :: String -> { | UnsafeRequestOptions } -> Effect Request
111+unsafeNew = runEffectFn2 _unsafeNew
112+
113+new :: String -> { | RequestOptions } -> Effect Request
114+new url options = runEffectFn2 _unsafeNew url (toUnsafeOptions options)
115+
116+new' :: forall r. BuildRequestOptions { | r } => String -> { | r } -> Effect Request
117+new' url options = runEffectFn2 _unsafeNew url (toUnsafeOptions (buildRequestOptions options))
118+
119+class BuildRequestOptions a where
120+ buildRequestOptions :: a -> { | RequestOptions }
121+
122+instance buildRequestOptionsRecord
123+ :: ( RowList.RowToList r rl
124+ , ConvertOptions rl r r'
125+ , Row.Union r' RequestOptions r''
126+ , Row.Nub r'' RequestOptions
127+ )
128+ => BuildRequestOptions { | r } where
129+ buildRequestOptions r = merge (Record.build (convertOptions (RLProxy :: _ rl)) r) defaultOptions
130+
131+class ConvertOptions (rl :: RowList) (input :: # Type) (output :: # Type) | rl input -> output where
132+ convertOptions :: RLProxy rl -> Record.Builder { | input } { | output }
133+
134+instance convertOptionsCons ::
135+ ( ConvertOptions rest input' output
136+ , ConvertOption field from to
137+ , Row.Cons field from rx input
138+ , Row.Cons field to rx input'
139+ , IsSymbol field
140+ ) => ConvertOptions (RowList.Cons field from rest) input output where
141+ convertOptions _ =
142+ convertOptions (RLProxy :: _ rest)
143+ <<< Record.modify (SProxy :: _ field) (convertOption (SProxy :: _ field))
144+
145+instance convertOptionsNil :: ConvertOptions RowList.Nil r r where
146+ convertOptions _ = identity
147+
148+class ConvertOption (field :: Symbol) from to | field -> to where
149+ convertOption :: SProxy field -> from -> to
150+
151+instance convertMethod :: ConvertOption "method" Method Method where
152+ convertOption _ = identity
153+
154+instance convertBody :: ConvertOption "body" RequestBody RequestBody where
155+ convertOption _ = identity
156+
157+instance convertBodyString :: ConvertOption "body" String RequestBody where
158+ convertOption _ = RequestBody.fromString
159+
160+instance convertBodyBuffer :: ConvertOption "body" ArrayBuffer RequestBody where
161+ convertOption _ = RequestBody.fromArrayBuffer
162+
163+instance convertBodyView :: ConvertOption "body" (ArrayView t) RequestBody where
164+ convertOption _ = RequestBody.fromArrayView
165+
166+instance convertHeaders :: ConvertOption "headers" Headers Headers where
167+ convertOption _ = identity
168+
169+instance convertHeadersRecord :: Homogeneous r String => ConvertOption "headers" { | r } Headers where
170+ convertOption _ = Headers.fromRecord
171+
172+instance convertHeadersObject :: ConvertOption "headers" (Object String) Headers where
173+ convertOption _ = Headers.fromObject
174+
175+instance convertHeadersArray :: ConvertOption "headers" (Array (Tuple String String)) Headers where
176+ convertOption _ = Headers.fromFoldable
177+
178+instance convertCache :: ConvertOption "cache" RequestCache RequestCache where
179+ convertOption _ = identity
180+
181+instance convertMode :: ConvertOption "mode" RequestMode RequestMode where
182+ convertOption _ = identity
183+
184+instance convertReferrer :: ConvertOption "referrer" Referrer (Maybe Referrer) where
185+ convertOption _ = Just
186+
187+instance convertReferrerPolicy :: ConvertOption "referrerPolicy" ReferrerPolicy ReferrerPolicy where
188+ convertOption _ = identity
189+
190+instance convertIntegrity :: ConvertOption "integrity" Integrity Integrity where
191+ convertOption _ = identity
src/Web/Fetch/RequestBody.jsnew file+5
@@ -0,0 +1,5 @@
1+exports.fromArrayBuffer = function(a) { return a };
2+exports.fromArrayView = function(a) { return a };
3+exports.fromString = function(a) { return a };
4+exports.fromReadableStream = function(a) { return a };
5+exports.empty = null;
src/Web/Fetch/RequestBody.pursnew file+16
@@ -0,0 +1,16 @@
1+module Web.Fetch.RequestBody where
2+
3+import Data.ArrayBuffer.Types (ArrayBuffer, ArrayView, Uint8Array)
4+import Web.Streams.ReadableStream (ReadableStream)
5+
6+foreign import data RequestBody :: Type
7+
8+foreign import fromArrayBuffer :: ArrayBuffer -> RequestBody
9+
10+foreign import fromArrayView :: forall a. ArrayView a -> RequestBody
11+
12+foreign import fromString :: String -> RequestBody
13+
14+foreign import fromReadableStream :: ReadableStream Uint8Array -> RequestBody
15+
16+foreign import empty :: RequestBody
src/Web/Fetch/RequestCache.pursnew file+30
@@ -0,0 +1,30 @@
1+module Web.Fetch.RequestCache where
2+
3+import Data.Maybe (Maybe(..))
4+
5+data RequestCache
6+ = Default
7+ | NoStore
8+ | Reload
9+ | NoCache
10+ | ForceCache
11+ | OnlyIfCached
12+
13+toString :: RequestCache -> String
14+toString = case _ of
15+ Default -> "default"
16+ NoStore -> "no-store"
17+ Reload -> "reload"
18+ NoCache -> "no-cache"
19+ ForceCache -> "force-cache"
20+ OnlyIfCached -> "only-if-cached"
21+
22+fromString :: String -> Maybe RequestCache
23+fromString = case _ of
24+ "default" -> Just Default
25+ "no-store" -> Just NoStore
26+ "reload" -> Just Reload
27+ "no-cache" -> Just NoCache
28+ "force-cache" -> Just ForceCache
29+ "only-if-cached" -> Just OnlyIfCached
30+ _ -> Nothing
src/Web/Fetch/RequestCredentials.pursnew file+21
@@ -0,0 +1,21 @@
1+module Web.Fetch.RequestCredentials where
2+
3+import Data.Maybe (Maybe(..))
4+
5+data RequestCredentials
6+ = Omit
7+ | SameOrigin
8+ | Include
9+
10+toString :: RequestCredentials -> String
11+toString = case _ of
12+ Omit -> "omit"
13+ SameOrigin -> "same-origin"
14+ Include -> "include"
15+
16+fromString :: String -> Maybe RequestCredentials
17+fromString = case _ of
18+ "omit" -> Just Omit
19+ "same-origin" -> Just SameOrigin
20+ "include" -> Just Include
21+ _ -> Nothing
src/Web/Fetch/RequestMode.pursnew file+24
@@ -0,0 +1,24 @@
1+module Web.Fetch.RequestMode where
2+
3+import Data.Maybe (Maybe(..))
4+
5+data RequestMode
6+ = Cors
7+ | NoCors
8+ | SameOrigin
9+ | Navigate
10+
11+toString :: RequestMode -> String
12+toString = case _ of
13+ Cors -> "cors"
14+ NoCors -> "no-cors"
15+ SameOrigin -> "same-origin"
16+ Navigate -> "navigate"
17+
18+fromString :: String -> Maybe RequestMode
19+fromString = case _ of
20+ "cors" -> Just Cors
21+ "no-cors" -> Just NoCors
22+ "same-origin" -> Just SameOrigin
23+ "navigate" -> Just Navigate
24+ _ -> Nothing
src/Web/Fetch/RequestRedirect.pursnew file+21
@@ -0,0 +1,21 @@
1+module Web.Fetch.RequestRedirect where
2+
3+import Data.Maybe (Maybe(..))
4+
5+data RequestRedirect
6+ = Follow
7+ | Error
8+ | Manual
9+
10+toString :: RequestRedirect -> String
11+toString = case _ of
12+ Follow -> "follow"
13+ Error -> "error"
14+ Manual -> "manual"
15+
16+fromString :: String -> Maybe RequestRedirect
17+fromString = case _ of
18+ "follow" -> Just Follow
19+ "error" -> Just Error
20+ "manual" -> Just Manual
21+ _ -> Nothing
src/Web/Fetch/Response.jsnew file+47
@@ -0,0 +1,47 @@
1+exports.headers = function (resp) {
2+ return resp.headers;
3+};
4+
5+exports.ok = function (resp) {
6+ return resp.ok;
7+};
8+
9+exports.redirected = function (resp) {
10+ return resp.redirected;
11+};
12+
13+exports.status = function (resp) {
14+ return resp.status;
15+};
16+
17+exports.statusText = function (resp) {
18+ return resp.statusText;
19+};
20+
21+exports.url = function (resp) {
22+ return resp.url;
23+};
24+
25+exports.body = function (resp) {
26+ return function() {
27+ return resp.body;
28+ };
29+};
30+
31+exports.arrayBuffer = function (resp) {
32+ return function() {
33+ return resp.arrayBuffer();
34+ };
35+};
36+
37+exports.blob = function (resp) {
38+ return function() {
39+ return resp.blob();
40+ };
41+};
42+
43+exports.text = function (resp) {
44+ return function() {
45+ return resp.text();
46+ };
47+};
src/Web/Fetch/Response.pursnew file+30
@@ -0,0 +1,30 @@
1+module Web.Fetch.Response where
2+
3+import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array)
4+import Effect (Effect)
5+import Web.Fetch.Headers (Headers)
6+import Web.File.Blob (Blob)
7+import Web.Promise (Promise)
8+import Web.Streams.ReadableStream (ReadableStream)
9+
10+foreign import data Response :: Type
11+
12+foreign import headers :: Response -> Headers
13+
14+foreign import ok :: Response -> Boolean
15+
16+foreign import redirected :: Response -> Boolean
17+
18+foreign import status :: Response -> Int
19+
20+foreign import statusText :: Response -> String
21+
22+foreign import url :: Response -> String
23+
24+foreign import body :: Response -> Effect (ReadableStream Uint8Array)
25+
26+foreign import arrayBuffer :: Response -> Effect (Promise ArrayBuffer)
27+
28+foreign import blob :: Response -> Effect (Promise Blob)
29+
30+foreign import text :: Response -> Effect (Promise String)