Skip to content

Instantly share code, notes, and snippets.

@manchicken
Created October 15, 2021 14:38
Show Gist options
  • Save manchicken/e8acd65e9f9067b28d1c25f89d54827d to your computer and use it in GitHub Desktop.
Save manchicken/e8acd65e9f9067b28d1c25f89d54827d to your computer and use it in GitHub Desktop.
url-string-antipattern-after
const { URL, URLSearchParams } = require('url')
const BASE_URL = 'https://api.foobar.com/api/bookmark'
const bookmark_url = 'https://www.reddit.com/r/chickens/search/?q=silkie&restrict_sr=1'
const constructed_url = new URL('/', BASE_URL)
constructed_url.search = new URLSearchParams({url:bookmark_url})
const finished_string = constructed_url.toString()
console.log(finished_string)
console.log(new URL(finished_string))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment