diff --git a/playground/index.html b/playground/index.html index 2696c92..1a0f03f 100644 --- a/playground/index.html +++ b/playground/index.html @@ -8,8 +8,7 @@

Cross fetch

diff --git a/src/Fido.ts b/src/Fido.ts index ff5a901..227a6db 100644 --- a/src/Fido.ts +++ b/src/Fido.ts @@ -1,6 +1,5 @@ export * from './Fido_sources.gen'; -export { requestGet } from './web/FidoJs.gen'; +export { getGeoService } from './web/FidoJs.gen'; -// export { -// } from './Fido_types.gen'; +export * from './Fido_types.gen'; diff --git a/src/Fido_sources.re b/src/Fido_sources.re index 08447f8..62a7cc9 100644 --- a/src/Fido_sources.re +++ b/src/Fido_sources.re @@ -1,4 +1,4 @@ -// open Fido_types; +open Fido_types; [@genType] -let requestGet = Http.Client.fetch; +let getGeoService = Http.Client.get("https://geo.6play.fr/v1/geoInfo/"); diff --git a/src/Fido_types.re b/src/Fido_types.re index 8b13789..58929e5 100644 --- a/src/Fido_types.re +++ b/src/Fido_types.re @@ -1 +1,11 @@ - +[@genType] +type geoServiceType = { + timezone: string, + offset: int, + isp: string, + country_code: string, + asn: string, + ip: string, + is_anonymous: bool, + areas: list(int), +}; diff --git a/src/dune/Fido.re b/src/dune/Fido.re index dec627c..67db721 100644 --- a/src/dune/Fido.re +++ b/src/dune/Fido.re @@ -1 +1,2 @@ module Types = Fido_types; +/* include Fido_sources; */ diff --git a/src/include/http_js/Client_js.re b/src/include/http_js/Client_js.re index 83024d9..50ac5f1 100644 --- a/src/include/http_js/Client_js.re +++ b/src/include/http_js/Client_js.re @@ -1,6 +1,8 @@ -let fetch = (~path: string) => +let get = (path: string, ()) => Js.Promise.( - Fetch.fetch(path) - |> then_(Fetch.Response.text) - |> then_(text => print_endline(text) |> resolve) + Fetch.fetchWithInit(path, Fetch.RequestInit.make(~mode=CORS, ())) + |> then_(Fetch.Response.json) + |> then_(json => Js.Json.decodeObject(json) |> resolve) + |> then_(opt => Belt.Option.getExn(opt) |> resolve) + |> then_(items => Js.log(items) |> resolve) ); diff --git a/src/include/http_native/Client_native.re b/src/include/http_native/Client_native.re index b15c041..71a1624 100644 --- a/src/include/http_native/Client_native.re +++ b/src/include/http_native/Client_native.re @@ -1,4 +1,4 @@ -let fetch = (~path: string) => +let get = (path: string, ()) => Fetch.( fetch(path) |> Lwt.map( diff --git a/src/web/FidoJs.re b/src/web/FidoJs.re index 08447f8..62a7cc9 100644 --- a/src/web/FidoJs.re +++ b/src/web/FidoJs.re @@ -1,4 +1,4 @@ -// open Fido_types; +open Fido_types; [@genType] -let requestGet = Http.Client.fetch; +let getGeoService = Http.Client.get("https://geo.6play.fr/v1/geoInfo/");