I use Fetch ( Fetch API ) in the project, and I would like, for sequence purposes, to create a function that receives all parameters such as method, url and data, and creates the correct request, depending on the GET or POST request.
Is it possible, using Fetch, to send a data object that, for a GET request, converts the data and builds it with parameters, and if it is a POST request, it simply sends the data object to the body?
It will look like this:
fetch ('/test', {
method: 'GET',
data: {
test: 'test'
}
});
This doubt was inspired by this jQuery ajax behavior:
$.ajax({
url: '/test',
method: 'GET',
data: {
test: 'test'
}
});
This will call this request:
'/test/?test=test'
source
share