Effect CommunityEC
Effect Community13h ago
2 replies
danielo515

Clarification on `HttpClient`, `HttpClientRequest`, and `HttpClientResponse` Roles

Everytime I stop using this methods for a while I have the same doubts when I come back to them. I'm a bit confused about the different roles of HttpClientRequest, HttpClientResponse and HttpClient.
My understanding is that everything under HttpClient is for creating clients or modifying their behavior, so for example HttpClient.filterStatusOk will make the client error on non 2XX responses.
However there is also the same method in HttpClientResponse, but I can't just pipe a request to that like this:

      const response = yield* httpClient
        .get(url, {
          headers: {
            Authorization: `Bearer ${token.access_token}`,
            Accept: "application/json",
          },
        })
        .pipe(HttpClientResponse.filterStatusOk)


The clients generated by HttpClient.HttpClient seems to be capable of execute request directly through .post ,.get and friends, but there is also the execute where you can build HttpCLientRequests like this:
  const getResp = yield* client
    .execute(
      HttpClientRequest.get("/get").pipe(
        HttpClientRequest.setUrlParams({ hello: "world" }),
      ),
    )


I'm a bit confused about when to use which one and what are the parts that are compatible and the ones that are incompatible.
Is it better to filter for statusOk when creating the client? Or when handling the responses? I gues that will be different based on each situation of course, but what people tend to do more?
Was this page helpful?