Code Drawer
1 min
type userprofile = { id string; email string; fullname string; plan "free" | "pro" | "enterprise"; }; export async function getuserprofile(userid string) promise\<userprofile> { const response = await fetch(`https //api example com/v1/users/${userid}`, { method "get", headers { accept "application/json", authorization `bearer ${process env api token ?? ""}` } }); if (!response ok) { throw new error(`failed to fetch profile (${response status})`); } return (await response json()) as userprofile; }{ "id" "usr 8f3b91", "email" "ava\@company com", "fullname" "ava williams", "plan" "pro" }
Have a question?
Our knowledgeable support team and an awesome community will get you an answer in a flash.
To ask a question or participate in discussions, you'll need to authenticate first.
