How to get the query string parameters and path in a Cloudflare worker
•
1 min read
Here the tip to get the string URL parameters:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest (request) {
const { search, pathname } = new URL(request.url)
}
Using the URL class we can extract the different parts of the URL requested:
searchis the query string, such as?p=1&p=2...pathnameis the path after the domain, such as/my/path/is