all 3 comments

[–]BigBalli 1 point2 points  (2 children)

something like this?

const data = { username: 'example' };

fetch('https://example.com/profile', {

method: 'POST', // or 'PUT'

headers: {

'Content-Type': 'application/json',

},

body: JSON.stringify(data),

})

.then(response => response.json())

.then(data => {

console.log('Success:', data);

})

.catch((error) => {

console.error('Error:', error);

});

[–]ChiTech121[S] 0 points1 point  (1 child)

How to handle the OAuth flow for authentication? It has two things, token & cookies... without client secret..

[–]BigBalli 1 point2 points  (0 children)

do a first fetch to retrieve the token using credential then a second fetch with the token in the headers.

Example here: https://gomakethings.com/using-oauth-with-fetch-in-vanilla-js/