{{ item.sample_body }}
{% endif %}
If the request happens on the same origin, then the X-CSRF-TOKEN is passed in conjunction with the access_token_cookie cookie.
{% if item.method in ['POST', 'PATCH'] %}const postData = {{ item.sample_body }};
{% endif %}fetch("{{ url_root }}{{ item.endpoint_example }}", {
method: "{{ item.method }}",
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf }}'
}{% if item.method in ['POST', 'PATCH'] %},
body: JSON.stringify(postData){% endif %}
})
.then(response => response.json())
.then(data => {
console.log(data);
});
If the request happens on a different origin, then no cookies are used, and the token is passed as an "Authorization" header using "Bearer" authentication.
{% if item.method in ['POST', 'PATCH'] %}const postData = {{ item.sample_body }};
{% endif %}fetch("{{ url_root }}{{ item.endpoint_example }}", {
method: "{{ item.method }}",
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{ access_token }}'
}{% if item.method in ['POST', 'PATCH'] %},
body: JSON.stringify(postData){% endif %}
})
.then(response => response.json())
.then(data => {
console.log(data);
});
import requests
{% if item.method in ['POST', 'PATCH'] %}
post_data = {{ item.sample_body }};
response = requests.{{ item.method|lower }}(
'{{ url_root }}{{ item.endpoint_example }}',
json=post_data,
headers={
'Authorization': 'Bearer {{ access_token }}'
}
)
print('Status Code:', response.status_code)
print(response.json()){% else %}
response = requests.{{ item.method|lower }}(
'{{ url_root }}{{ item.endpoint_example }}',
headers={
'Authorization': 'Bearer {{ access_token }}'
}
)
print('Status Code:', response.status_code)
print(response.json()){% endif %}