Skip to content

Instantly share code, notes, and snippets.

@TheUltDev
Created January 17, 2020 03:37
Show Gist options
  • Save TheUltDev/a2e0d0f5ac38eaacd299ee3992c412a6 to your computer and use it in GitHub Desktop.
Save TheUltDev/a2e0d0f5ac38eaacd299ee3992c412a6 to your computer and use it in GitHub Desktop.
export async function post(
path: string,
options?: object,
token?: string,
): Promise<Response> {
const body = new URLSearchParams({
'response_format': 'json',
'application_id': API_ID.toString(),
'session_token': token || undefined,
...options,
}).toString();
const absolute = path.indexOf(ORIGIN) !== -1;
const endpoint = absolute ? path : `${API_HOST}/${path}`;
const response = await fetch(`${endpoint}.php`, {method: 'POST', body});
const json = await response.json();
return json.response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment