✅ Web things minimal api
after tons of codding i totally forgot what i wanted to do lmao, so problem is - product has click eventhandler, which gets id of product from attribute, how do i send back html page of product and data? or should i send html page first, and after send data based on "6" from localhost/product/6 ?
30 Replies
which is most common way?
... what?
You say minimal api, but this is clearly a graphical client of some sort. Blazor? javascript?
i mean
thats my code rn
and for your routes,
product/{id}
would make senseproblem with product/{id] is, i cant send html file
Where is
SendHtml
from?minimal APIs are primarily for building.. well, APIs
my method
forgot
stry
not full stack webpages
okay, so you're serving static html pages via minimal api endpoints
thats not a great idea lol, but okay :p
so, rn im putting clicked div's id into cookies and all divs gonna redirect to /product, then onload i will request specific product by id from cookies
should i send them as static files?
or what
I'm not really sure exactly what you are trying to do here
You're abusing minimal APIs to serve html instead of just JSON, and Im guessing your html pages contain javascript to do interactivity
so, ill try to explain
I'd probably make a normal javascript frontend application and serve that via static files and just have a normal json-serving API with that
yeah this is some cursed homebrew stuff 😄
You probably can make it work, but its gonna get funky
incase "/" im doing that,
so
mhm.
onload i request all data and create divs with it
it kinda seems like you are re-inventing MVC, but in minimal APIs
i mean
i can make it work
with cookies
just wanted to clarify, maybe here is a better way
looks like i had to wait till mvc course lmao
so, rn when i click to div, im redirecting to default product page, without {id}, and have id in cookies, so onload i will request product from db by id
the thing is, you're not really doing serverside rendered html here, you're just serving static html with vanilla JS to provide interactivity
but why are you putting stuff in cookies?
just redirect to
product/{id}
dont abuse cookies :pthere was other problem
with loading css and js from static files
I just want you to be aware that what you are doing is... uh.. extremely unorthodox
this is NOT how you build webpages normally
that said, you can absolutely keep doing you for learning
but I dont see the point of your "SendHtml" routes at all tbh
serve your entire frontend as static files, and have only api routes in the BE
so, incase of index.html is in staticfiles folder, what i need to do, for user see it? i mean, program starts with "/" path, no?
ok
i get it
yep!
it works with index page, but with different pages still need extension name
well, you could fix that easily
just move your
products.html
to /products/index.html
but tbh, I think you'd benefit greatly from picking up a real frontend app framework
or just find some javascript routing library, Im sure something like that exists
or move to full on serverside rendered html, using razor pages or MVCyeah
looks like its the way
ill do this thing
abusing cookies
but new projecs will be on mvc/razor pages
thx for helping anywa 🙂