Code Monkey home page Code Monkey logo

relude-fetch's People

Contributors

andywhite37 avatar dependabot[bot] avatar mlms13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

relude-fetch's Issues

Example code without infix operators

I'm struggling to understand the decoding example in the tests

    let decode: Js.Json.t => Belt.Result.t(t, string) =
      json => {
        make
        <$> JD.intFor("userId", json)
        <*> JD.intFor("id", json)
        <*> JD.stringFor("title", json)
        <*> JD.boolFor("completed", json)
        |> Relude.Result.fromValidation
        |> Relude.Result.mapError(_ => "Decode failed");
      };

Would this be equal to the following?

let decode: Js.Json.t => Belt.Result.t(t, string) =
      json => {
        make
        |> map(JD.intFor("userId", json))
        |> ap(JD.intFor("id", json))
        |> ap(JD.stringFor("title", json))
        |> ap(JD.boolFor("completed", json))
        |> Relude.Result.fromValidation
        |> Relude.Result.mapError(_ => "Decode failed");
      };

With some direction, I'd be glad to open a PR adding examples sans infix operators. It would be nice to able to see the two versions side by side for mere mortals like I.

Require `fetch` object to be passed in

Currently, we're assuming (really, bs-fetch is assuming) that the fetch global exists. This is true for browsers, but for other environments like Node or React Native, this requires a polyfill like isomorphic-fetch or cross-fetch. Importing one of those libraries purely for the side-effect of attaching junk to the global object is really gross (and worse, it's easy to forget to do, which could cause things to break at runtime).

I'm definitely open to ideas, but it seems like the safest thing to do would be to expect ReludeFetch to be constructed with a Fetch object (module?) that provides the actual fetch implementation. In a more perfect world, maybe we'd have a trifunctor IO like ZIO where the Fetch interface could just be part of the environment.

Type mismatch between the output of fetch post and ensure2xx

Hi guys, thanks for the awesome libraries!

I tried to do this using ReludeFetch but the code couldn't comple since the output of ReludeFetch.post is not compatible with the input of ReludeFetch.Response.StatusCode.ensure2xx.

module IO = Relude.IO;
module Error = ReludeFetch.Error;

module IOE = IO.WithError({
  type t = Error.t(Decco.decodeError)
})

[@decco encode]
type request = {
  username: string,
  password: string,
};

[@decco decode]
  type response = {
  token: string,
};

let login = (~username, ~password) => {
    ReludeFetch.post(
      ~headers=Headers.acceptJson,
      ~body=
        ReludeFetch.Body.Content.Json(
          request_encode({
            username,
            password,
          }),
        ),
       "/some/login",
    )
    >>= ReludeFetch.Response.StatusCode.ensure2xx;
  };
};

When I look at the this it has Relude.IO.t(Fetch.response, Error.t('decodeError)) but it should be Fetch.Response.t. Am I compose the wrong function here?

Fetch example?

I've been trying to use this library, but hit a wall when trying to work with the response. I'm not sure if this is an error on my side (understanding) or issue with the library as I'm getting the following error with the demo example too:

open Relude;

// Defines our API error type
module Error = {
  type t = ReludeFetch.Error.t(string);
  let show = error => ReludeFetch.Error.show(a => a, error);
  module Type = {
    type nonrec t = t;
  };
};

// Open the IO infix operators
module IOE = IO.WithError(Error.Type);
open IOE.Infix;

let textResponse = ReludeFetch.fetch("some_url") >>= ReludeFetch.Response.text;

Last line errors with:

Error: This expression has type
         Fetch.Response.t => Relude.IO.t(string, ReludeFetch_Error.t('a))
       but an expression was expected of type
         Fetch.response => IOE.Monad.t('b)
       Type Fetch.Response.t is not compatible with type Fetch.response

Add more docs

Link to relude's IO documentation for info on IO.

Provide an example of using the IO-based fetch - e.g. in a ReasonReact app?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.