Skip to content

What is the best way to make HTTP requests during SSR? #581

Answered by gbj
Zk2u asked this question in Q&A
Discussion options

You must be logged in to vote

The dead-simple solution would be to create the reqwest connection in the main function in main.rs and store it in a static OnceCell, then access it in the server API.

The slightly-more-complicated one would be to provide it with the context API by using leptos_routes_with_context instead of leptos_routes and providing the connection with provide_context()

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Zk2u
Comment options

@gbj
Comment options

@Zk2u
Comment options

@Zk2u
Comment options

@Zk2u
Comment options

Answer selected by Zk2u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants