UNPKG

fastapi-rtk

Version:

A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.

33 lines (32 loc) 994 B
import { createFetchParams, urlJoin } from "fastapi-rtk/utils"; async function getUser(baseUrl, signal) { const { fetchPath, options } = createFetchParams({ path: urlJoin(baseUrl, "auth/user"), method: "GET" }); const res = await fetch(fetchPath, { signal, ...options }); const data = await res.json(); if (!res.ok) { const errorMessage = typeof data.message === "string" ? data.message : JSON.stringify(data.message, null, 2); throw new Error(errorMessage); } return data; } async function updateUser(baseUrl, userData) { const { fetchPath, options } = createFetchParams({ path: urlJoin(baseUrl, "auth/user"), method: "PUT", body: userData }); const res = await fetch(fetchPath, options); const data = await res.json(); if (!res.ok) { const errorMessage = typeof data.message === "string" ? data.message : JSON.stringify(data.message, null, 2); throw new Error(errorMessage); } return data; } export { getUser, updateUser };