Helper Functions
Preparing Init
The following functions will initialize the RequestInit
object for specific use-cases.
All of them will setcredentials
to "include"
and a header Accept
with value of "application/json"
prepareGet
prepares a GET requestpreparePost/Patch/Put/Delete
prepares a form-data POST/PATCH/PUT/DELETE request.preparePostUrlEncoded
prepares a form url-encoded POST requestprepareFormDataPost
prepares a POST request with aFormData
object and detects if it contains files.- if it contains files, it will call
preparePost
and set the body to the formData object. - otherwise
preparePostUrlEncoded
will be called and the properties of the formData will be set accordingly.
- if it contains files, it will call
You don't need to use them. You can write your own code to initialize the RequestInit
object. These are just here for convenience.