type Github = {
token: string;
};
/**
* Follow a user
* Note that you'll need to set `Content-Length` to zero when calling out to this endpoint. For more information, see "[HTTP verbs](https://docs.github.com/rest/overview/resources-in-the-rest-api#http-verbs)."
Following a user requires the user to be logged in and authenticated with basic auth or OAuth with the `user:follow` scope.
*/
export async function main(auth: Github, username: string) {
const url = new URL(`https://api.github.com/user/following/${username}`);
const response = await fetch(url, {
method: "PUT",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 486 days ago