# Bonito method to get URL within App

**URL:** https://discourse.julialang.org/t/bonito-method-to-get-url-within-app/122289
**Category:** Visualization
**Tags:** question
**Created:** [November 5, 2024, 2:51pm UTC](https://discourse.julialang.org/t/bonito-method-to-get-url-within-app/122289 "2024-11-05T14:51:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)
#### Post date: [November 5, 2024, 2:51pm UTC](https://discourse.julialang.org/t/bonito-method-to-get-url-within-app/122289/1 "2024-11-05T14:51:00Z")

</div>

currently i’m piecing the URL together from the Session argument as follows, but it’d be nice if there were an exported public way to do this. or did i miss it?

```julia
App() do session::Session
       server = session.connection.connection.server
       DOM.div(string(server.protocol, server.url, ':', server.port, server.routes.table[1].first))
end

```

[EDIT: updated code to actually work]

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [November 5, 2024, 2:59pm UTC](https://discourse.julialang.org/t/bonito-method-to-get-url-within-app/122289/2 "2024-11-05T14:59:26Z")

</div>

What do you want to do exactly?  
There are multiple ways to get the servers public url.

---

<div class="post-metadata">

### Author: ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)
#### Post date: [November 5, 2024, 3:05pm UTC](https://discourse.julialang.org/t/bonito-method-to-get-url-within-app/122289/3 "2024-11-05T15:05:42Z")

</div>

i want to do exactly that-- programmatically get the servers public URL, so i can either display it on the page or better yet copy it to the clipboard on a button press. thx!

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [November 5, 2024, 3:14pm UTC](https://discourse.julialang.org/t/bonito-method-to-get-url-within-app/122289/4 "2024-11-05T15:14:59Z")

</div>

I guess you can use:

```julia
using Bonito

get_server(session::Session) = get_server(session.asset_server)
get_server(server::HTTPAssetServer) = server.server
get_server(server::Bonito.ChildAssetServer) = get_server(server.parent)
get_server(any) = error("Not an HTTP server for session")

App() do session::Session
    server = get_server(session)
    DOM.div(string(Bonito.online_url(server, "")))
end

```

Would be cool if this works:

```julia
App() do session::Session
    DOM.div(Bonito.Link("/"))
end

```

This doesn’t work right now, but I think that could fall under the use cases for `Link`.

---

<div class="post-metadata">

### Author: ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)
#### Post date: [November 5, 2024, 3:28pm UTC](https://discourse.julialang.org/t/bonito-method-to-get-url-within-app/122289/5 "2024-11-05T15:28:49Z")

</div>

thanks! those new `get_server` definitions would be handy to have in Bonito. and i guess i misunderstood the docstring for `online_url`– i interpreted that as _setting_ the URL, not getting it.
