/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-url-a4e26b0675a7-url-s0058-c0000.md
`$url()` - hono-docs
$url() Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt url Summary You can get a URL object for a...
$url()
Source evidence: /Sources/raw/honojshono/honojshono.md Canonical citation: https://hono.dev/llms-full.txt#url
Summary
You can get a URL object for accessing the endpoint by using $url(). ::: warning You have to pass in an absolute URL for this to work. Passing in a relative URL / will result in the following error. `Uncaught TypeError: Failed to c...
Content
You can get a URL object for accessing the endpoint by using $url().
::: warning
You have to pass in an absolute URL for this to work. Passing in a relative URL / will result in the following error.
Uncaught TypeError: Failed to construct 'URL': Invalid URL
// ❌ Will throw error
const client = hc<AppType>('/')
client.api.post.$url()
// ✅ Will work as expected
const client = hc<AppType>('http://localhost:8787/')
client.api.post.$url():::
const route = app
.get('/api/posts', (c) => c.json({ posts }))
.get('/api/posts/:id', (c) => c.json({ post }))
const client = hc<typeof route>('http://localhost:8787/')
let url = client.api.posts.$url()
console.log(url.pathname) // `/api/posts`
url = client.api.posts[':id'].$url({
param: {
id: '123',
},
})
console.log(url.pathname) // `/api/posts/123`