const url = '{{ request.build_absolute_uri }}'
{% if 'GET' in allowed_methods %}
// GET Request
fetch(url)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error))
{% endif %}
{% if 'POST' in allowed_methods %}// POST Request
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({...}),
})
.then(response => response.json())
.then(data => console.log('Success:', data))
.catch(error => console.error('Error:', error))
{% endif %}
{% if 'PUT' in allowed_methods %}// PUT Request
fetch(url, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({...}),
})
.then(response => response.json())
.then(data => console.log('Success:', data))
.catch(error => console.error('Error:', error))
{% endif %}
{% if 'PATCH' in allowed_methods %}// PATCH Request
fetch(url, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({...}),
})
.then(response => response.json())
.then(data => console.log('Success:', data))
.catch(error => console.error('Error:', error))
{% endif %}
{% if 'DELETE' in allowed_methods %}// DELETE Request
fetch(url, { method: 'DELETE' })
.then(response => console.log('Item deleted:', response))
.catch(error => console.error('Error:', error))
{% endif %}