One thing I figured out almost immediately is that I can do what I want 
with ${ request.resource_url(resource, host=api_url) }

Where the api_url is configured at runtime. That might be the simplest way 
to do things. But I will look into aiopyramid as mentioned.

Thanks!

On Sunday, November 24, 2019 at 12:40:02 AM UTC-6, Andrew Martin wrote:
>
> Hi there,
>
> I'd like to add a few real-time features to an existing pyramid app. 
> Notifications when queued tasks are complete and some real-time dashboards, 
> and chat.
>
> I'm thinking of an implementation that doesn't seem like it would be super 
> invasive, but I though I would check here and see if some of you more 
> experienced used see any obvious major problems first.
>
> Basically, I want to farm out the realtime elements to a websocket api 
> server. FastAPI seems like a good framework to do this. But I'd like to be 
> able to use the traversal machinery in pyramid to hit those endpoints in my 
> mako templates. So my javascript for opening the websocket can use 
> the request.resource_url() pattern and I don't have to do a ton of work to 
> figure out where in the external API I should be connecting.
>
> So for example if in my web app I'm at mywebsite.com/users/123456, then I 
> can have my websocket enpoint constructed by calling ${ 
> request.resource_url(request.api, 'users', '123456') } and it would 
> generate a URL as api.mywebsite.com/api/v1/users/123456 where "
> api.mywebsite.com/api/v1" is configured in the .ini file.
>
> To make that work I'd create a resource factory that adds the api property 
> to the Root object with the value set in the .ini file.
>
> The pyramid view would continue to provide the current values from a db 
> query, so there's a sane default to fall back on in case the websocket 
> can't connect. For authentication and authorization, I'd server the redis 
> instance I'm already using for server side sessions and just have the 
> FastAPI server check that session for whether or not the user is 
> authenticated/authorized or not.
>
> I think it should be relatively easy to share the SQLAlchemy models 
> between the two frameworks as well.
>
> Is this totally insane? Is there a better way to do this? Am I setting 
> myself for a world of pain that I'm not able to see right now? Just 
> wondering if anyone can offer any guidance before I buckle down and 
> implement this?
>
> I realize some of this is totally out of scope for this mailing list, and 
> I"m not asking anyone to comment on whether this is a good idea from the 
> FastAPI end of things. Just pretend that all just works. I'm really just 
> curious about the Pyramid implementation.
>
> thanks!
>
> -andrew
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/2deaba67-cca3-4cb5-8ef1-5b11a59c4087%40googlegroups.com.

Reply via email to