joriszwart.nl

I code dreams™

Accept header tests

HTTP Playground

Accept-type header tests

text/xml

text/plain

application/json, application/javascript

*/*

const load = async (url, accept = 'text/html') => {
    const headers = { accept }
    const response = await fetch(url, { headers })
    return await response.text()
}

load('/playground', 'text/xml')
    .then(r => document.querySelector('.text-xml').value = r)

load('/playground', 'text/plain')
    .then(r => document.querySelector('.text-plain').value = r)

load('/playground', 'application/json')
    .then(r => document.querySelector('.application-json').value = r)

load('/playground')
    .then(r => document.querySelector('.text-html').value = r)