Possible to open a form through an API call?

What I’m trying to do:

Hi folks, first time user. Am currently building an app for my course that needs to allow a page to be shown using a custom URL path (i.e. a HTTP endpoint). Currently, I’ve got it opening the startup form but I’ve tried a few methods that wouldn’t work with that method (As I’ve learned the hard way!)

What I’ve tried and what’s not working:

So like I’ve said, I have it directing to the startup page via a http request. Unfortunately the context object for opening the page is always going to say “browser” when what I was trying to do was get the startup form on initialization to check if it’s being called from an API endpoint.

That way, rather than render the rest of the template it would just open the form I wanted to access directly through the API.

I’ve also tried opening the form via the server module which obviously doesn’t work and I’ve also put some thought into making a startup client-side server module that would be called from the back-end server.

Essentially the API would call to start up the app with the API path as a string parameter, the client-side server module would check for any path passed in and initialize the relevant form with the default just being the default startup-form. I’m honestly not sure if this is possible, that was just thinking off the top of my head if that makes sense.

I can’t share any code/clone of my project as it’s for an assignment but if anyone has any tips/pointers to where I might find more help in the documentation or otherwise I would appreciate it! :blush:

I think you should look at the hash routing library, as it allows you to open a form based on the URL: HashRouting: Routing, navigation with URL Hash

2 Likes

Hey thanks for the reply/tip!

I’ve been trying to implement HashRouting unfortunately I keep getting errors stating there is no such module in my app.
Code (In startup form)

from HashRouting import routing

ImportError: No module named HashRouting

EDIT: I got it working, apologies! Joys of being a student, always learning haha. I got the URL hash routing working so thank you so much for the advice.

Glad you got it working! Hash routing is amazing, and I wouldn’t do an Anvil project without it these days (at least until Anvil incorporates actual routing).

1 Like