2025-02-23
2025-02-24
This commit is contained in:
parent
2212f4fc14
commit
0f52ff0cef
40 changed files with 846 additions and 75 deletions
30
src/libs/apis/clients.ts
Normal file
30
src/libs/apis/clients.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import type { Input } from "@effect/platform/UrlParams";
|
||||
|
||||
import { FetchHttpClient, HttpClient, HttpClientRequest, Url, UrlParams } from "@effect/platform";
|
||||
import { Effect, pipe } from "effect";
|
||||
|
||||
export const DebugHttpClient = pipe(
|
||||
HttpClient.HttpClient,
|
||||
Effect.andThen(HttpClient.tapRequest(Effect.logDebug)),
|
||||
Effect.andThen(HttpClient.tap(Effect.logDebug)),
|
||||
Effect.andThen(HttpClient.filterStatusOk),
|
||||
HttpClient.withTracerPropagation(false),
|
||||
Effect.provide(FetchHttpClient.layer),
|
||||
);
|
||||
|
||||
export const createUrlWithParams = (stringUrl: string) => (params: Input) =>
|
||||
Effect.gen(function*() {
|
||||
const url = yield* Url.fromString(stringUrl);
|
||||
const urlParams = UrlParams.fromInput(params);
|
||||
return Url.setUrlParams(url, urlParams);
|
||||
});
|
||||
|
||||
export const createGetHttpRequest = (url: URL): HttpClientRequest.HttpClientRequest =>
|
||||
pipe(
|
||||
HttpClientRequest.get(url),
|
||||
HttpClientRequest.bearerToken(import.meta.env["VITE_TMDB_API_KEY"]),
|
||||
HttpClientRequest.acceptJson,
|
||||
);
|
||||
|
||||
export const executeHttpRequest = (request: HttpClientRequest.HttpClientRequest) =>
|
||||
Effect.andThen(DebugHttpClient, client => client.execute(request));
|
||||
Loading…
Add table
Add a link
Reference in a new issue