Skip to content

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

Answered by gbj
617a7aa 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
@617a7aa
Comment options

@gbj
Comment options

@617a7aa
Comment options

@617a7aa
Comment options

@617a7aa
Comment options

Answer selected by 617a7aa
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