In this part, we are creating the HTTP POST method. Follow these steps to create the postHttp function:
- Create a constant called postHttp.
- Assign to that constant an asynchronous function that receives four arguments, url, body, type, and options. The type argument will have the default value of 'json'.
- In this function return, we will execute the baseHttp function, passing the url argument that we received, and 'post' as the second argument. In the third argument, we will pass an object with the body variable, and the deconstructed options argument that we received. Because of the currying property of baseHttp, we will execute the returned function with the type argument we received. The body is usually a JSON or a JavaScript object. If this request is going to be a file upload, body needs to be a FormData object:
export const postHttp = async (
url,
body,
type = 'json',
options,
) => (await baseHttp(url,
'post',
...