async function request() {
const url = "https://api.example.com/v1/users";
const options: RequestInit = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer my_secret_token_123",
},
body: JSON.stringify({
"name": "Thiago Lafite",
"email": "thiago@lafitelima.com.br",
"role": "admin"
}),
};
try {
const response = await fetch(url, options);
const result = await response.json();
console.log(result);
return result;
} catch (error) {
console.error("Fetch error:", error);
}
}
request();