Created
May 8, 2019 19:07
-
-
Save LukeMwila/d49831d43bafa25c741eb9ccd0125b49 to your computer and use it in GitHub Desktop.
Function that handles making api requests
This file contains hidden or 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
/** | |
* API Request | |
* @param endPoint - api endpoint | |
* @param httpMethod - the http method defining the type of request (POST/GET/PUT/PATCH) | |
* @param bodyParams - object with properties being passed with the request | |
*/ | |
export const apiRequest = async ( | |
endPoint: string, | |
httpMethod: string, | |
bodyParams?: object | |
): Promise<any> => { | |
const response = await fetch(endPoint, { | |
method: httpMethod, | |
headers: { | |
Accept: "application/json", | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify(bodyParams) | |
}); | |
return await response.json(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment