#๐Ÿ”’ How to connect back-end and front-end

25 messages ยท Page 1 of 1 (latest)

hazy river
#

We are writing a pet-project on python(FastApi) and raw js, and we don't know how to connect back-end and front-end,
We have api on 127.0.0.1:8000/api/manga/{name} and frontend on 127.0.0.1:5501/frontend/index.html
How we can edit frontend's url into /manga/{name} to get path parameter
It isn't a SPA we have 10+ endpoints and want to create every frontend's url for every endpoints
We need to get the name of the manga from the URL request, and then use the name to request information about the manga from the backend in order to display the data on the page. This means that when we click on a manga link in the catalog, we should be redirected to the manga page with the addition of a "name" parameter in the link. Based on this link, we can then load the page.

stark juncoBOT
#

@hazy river

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tacit delta
#

Are you asking how to send requests to your backend?

hazy river
#

No

#

how to get path parametr from frontend

#

and use it in query

#

for db

hazy river
#

so

#

that's a problem

night cedar
#

You just get rid of the /api/ prefix in the route within the FastAPI appp, from FastAPI app(base_url,...), from your reverse proxy, or from whatever's put it there.

#

I'm not sure what you mean exactly though. If your front end is a static file, you can create a route in FastAPI, and serve a FileResponse or something on /manga/{name} on it. The relative URLs withi index.html need to correctly match to URLs being served by something serving up the static imge assets and fonts etc. It's easier just to serve the front end by whatever its framework wants to be served with, and have that call into FastAPI routes.

hazy river
#

i need second server on fastapi with frontend?

hazy river
#

from frontend i can just take a html file

#

and then use it on my side?

#

but

#

i want two web-apps

#

one will be front

#

and another will restapi

#

how to do this

#

We need to get the name of the manga from the URL request, and then use the name to request information about the manga from the backend in order to display the data on the page. This means that when we click on a manga link in the catalog, we should be redirected to the manga page with the addition of a "name" parameter in the link. Based on this link, we can then load the page.

stark juncoBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.