Created
January 17, 2020 03:37
-
-
Save TheUltDev/a2e0d0f5ac38eaacd299ee3992c412a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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