frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

FastHTML Best Practices

https://www.fastht.ml/docs/ref/best_practice.html
32•tosh•1d ago

Comments

CraigJPerry•1d ago
Another day, another FastHTML post on HN, someone is active on the marketing front ;-)

Joking aside, enough of the premise resonated with me that i've been test driving it the past few days - i'm definitely target audience - and generally finding it pretty good.

I like the fact it's just functions and data, a lot of complexity has just been thrown in the bin. No bundler, no build/packaging step required etc etc but you'd have to be in the target audience to be happy with this[1]

For example when it comes to organising my thoughts, i don't need to learn some new paradigm, it's just functions, so i was able to just use regular basic concepts i'd use to organise any code. Concrete example: a template expressed as a function that takes a couple of parameters to inject somewhere makes for an easy to live with approach to reuse - since unlike a base.html in jinja2 for example, i can navigate to usages in my editor because it's just function composition. No templating DSL.

Another concrete example - i wanted something akin to a component in react, something with some state and an ability to render() - so i created a dumb plain old class, put the state as fields on the class and had a render method. Refreshingly basic. I didn't need a conventions guide or anything like that "here's how we do this in Framework X" - i just used basic how to write code principles.

I don't find the docs that consistent - for example the linked page (which i've never seen before) points out using @rt with function name for the route - i saw this was possible in an annotated claude chat they link from the github and immediately figured that's a 1000 better than @app.route("xxx") def post|get ... - but it has gotchas, AIUI just using rt creates a post and get handler by default - but it has benefits that i can use the function itself as the way to resolve the path (think url_for in other frameworks like django) - the docs are mostly littered with the awkward "you'll have lots of functions called get or post with a decorator specifying the route" approach.

The types .pyi is good enough for my use case (letting my editor look up what functions exist etc.) but it's incomplete if you want something like pyright to be happy on its strictest settings.

Their development process seems quite intriguing - all written in notebooks!

Their coding style is different from the approach you'd more commonly see (e.g. Black style formatting) but actually quite nice, it's more like Peter Norvig style (which i see as gold standard).

[1] i just want a python SSR webapp with html, minimal css and minimal js - to make it performant i'll lean on reverse proxying and etags in front of it

all2•1d ago
1. I don't use the internal DB stuff, I've been using Peewee ORM instead because it is more declarative (less magical) and fits in my head better.

2. I use app.get/post/etc. because it is more declarative. I like to know without thinking what sort of message an endpoint is expecting.

3. Query params: I don't know how I feel about this. There's some ambiguity in my head still about URL params vs query params.

4. Leveraging return values for DB model creation: This is syntactic sugar. It looks nice, but I prefer to have my code broken out so I can parse it mentally one piece at a time.

5. Use .to() for URL Generation: This is pretty cool I'll have to give this a try.

6. PicoCSS: I've been using this exclusively and it comes out rather nicely with a minimal amount of custom CSS.

7. Smart Defaults: Again, I prefer more declarative code, so I don't like this and I don't use it.

8. FastHTML Handles Iterables: I don't use this. I prefer list comprehensions when building out lists of components. An extra function call reads as confusing to me. Potato tomato.

9. Minimal Code: This is growing on me. I like one-liners for very short components or endpoints. It means I can fit more code on the screen at any given point in the file.

10. Use POST for All Mutations: I do this exclusively. I know htmx has other tags, but I don't use them because they muddy my understanding.

11. Modern HTMX Event Syntax: I haven't made enough use of HTMX to have to use this.

---

In all I've been very pleased with FastHTML and the speed at which I can build out an app. I'm nearly ready to release my first project in all its glory. It isn't much, but I've learned a bunch about web stuff by putzing around with it in the in-between times.

daft_pink•1d ago
I’m really curious if they’ve created a way to use FT components but use FastAPI to serve the HTMX
librasteve•1d ago
an intriguing post with the ubiquitous todo example

here’s how that looks in https://harcstack.org

  model Todo does Component::Red[:C:R:U:D] {
    also does HxTodo;

    has UInt   $.id      is serial;
    has Bool   $.checked is rw is column = False;
    has Str    $.text    is column is required;

    method toggle is controller {
        $!checked = !$!checked;
        $.^save;
        self
    }

    method HTML {
        tr
            td( input :type<checkbox>, |$.hx-toggle, :$!checked),
            td( $!checked ?? del $!text !! $!text),
            td( button :type<submit>, |$.hx-delete, :style<width:50px>, '-'),
    }
  }
  Todo.^create-table;
full code is here https://github.com/librasteve/Air-Play/blob/main/lib/Air/Pla...
all2•4h ago
Is this maybe in the wrong place? How does this relate to FastHTML best practices?
librasteve•2h ago
the HARC stack is quite similar to FastHTML … both are back end libraries that leverage HTMX to help build web apps on the server side and reduce the complexity of modern web development

specifically the OP references the todo example app and I thought readers here who are interested in server side web coding would like to see the same example done in another stack that is less hampered by the limitations of Python

Why You Should Move Your Site Away from Weebly (YC W07)

https://www.articulation.blog/p/why-you-should-move-your-site-away-from-weebly
1•dustywusty•4m ago•0 comments

Colorado kayakers rescue a dog that tumbled over 60-foot waterfall in Mexico

https://coloradosun.com/2025/06/03/kayakers-rescue-waterfall-trapped-dog/
1•mooreds•6m ago•0 comments

Portable device captures airborne molecules for noninvasive disease detection

https://phys.org/news/2025-05-portable-device-captures-airborne-molecules.html
1•PaulHoule•13m ago•0 comments

Why does C++ think my class is copy-constructible when it can't be?

https://devblogs.microsoft.com/oldnewthing/20250606-00/?p=111254
1•ibobev•13m ago•0 comments

Building a Modern Python API with Azure Cosmos DB: A 5-Part Video Series

https://devblogs.microsoft.com/cosmosdb/building-a-modern-python-api-with-azure-cosmos-db-a-5-part-video-series/
1•ibobev•14m ago•0 comments

Retro Game Sprites Generated in One Attempt with Ideogram's "V3 Quality" Model

https://gametorch.app/commons/image_models/ideogram-v3-quality
1•gametorch•18m ago•0 comments

Ask HN: What would you do if AGI were coming in 2-4 years?

1•atleastoptimal•18m ago•2 comments

Ask HN: Is synthetic data generation practical outside academia?

1•cpard•18m ago•0 comments

Palantir is nuts. When's the crash?

https://www.ft.com/content/747dd085-6c83-4c0b-a93e-e134a643f2dd
12•1vuio0pswjnm7•18m ago•1 comments

Apple Cash Management (2021)

https://www.treasurefi.com/blog/a-look-inside-apple-cash-management
2•walterbell•21m ago•0 comments

Subcontinental Genetic Variation in the All of Us Research Program

https://www.cell.com/ajhg/fulltext/S0002-9297(25)00173-9
1•bookofjoe•21m ago•0 comments

Show HN: SQLAlchemy just the core – a better way

https://github.com/sayanarijit/sqla-fancy-core
1•sayanarijit•23m ago•0 comments

Show HN: Automate any workflow with Osly and 10x your productivity

https://app.osly.ai/
2•hez2000•23m ago•0 comments

Anthropic releases custom AI chatbot for classified spy work

https://arstechnica.com/ai/2025/06/anthropic-releases-custom-ai-chatbot-for-classified-spy-work/
1•gametorch•26m ago•0 comments

A man rebuilding the last Inca rope bridge

https://www.atlasobscura.com/articles/last-inca-rope-bridge-qeswachaka-tradition
1•kaonwarb•29m ago•0 comments

NATS Comparison to Kafka, Rabbit, gRPC, and Others

https://docs.nats.io/nats-concepts/overview/compare-nats
1•teleforce•36m ago•0 comments

SchemaPin prevents "MCP Rug Pull" attacks

https://github.com/ThirdKeyAI/SchemaPin
2•smugglereal•37m ago•1 comments

Autocomp: LLM-Driven Code Optimization for Tensor Accelerators

https://charleshong3.github.io/blog/autocomp.html
1•matt_d•38m ago•0 comments

Jony Ive's LoveFrom helped design Rivian's first electric bike

https://techcrunch.com/2025/06/06/jony-ives-lovefrom-helped-design-rivians-first-electric-bike/
2•coloneltcb•56m ago•0 comments

Michigan triples waters with 'Do Not Eat' warning for PFAS in fish

https://www.mlive.com/environment/2025/06/michigan-triples-waters-with-do-not-eat-warning-for-pfas-in-fish.html
1•mahirsaid•57m ago•1 comments

Dear High Schoolers, Time Is Precious

https://byronsharman.com/blog/dear-high-schoolers
2•chilipepperhott•58m ago•0 comments

Show HN: Bridgit – In-Person-First Networking

https://www.bridgitsocial.com/
1•amfooladgar•58m ago•1 comments

Understanding MCP Evals: Why Evals Matter for MCP

https://huggingface.co/blog/mclenhard/mcp-evals
1•mooreds•58m ago•0 comments

Let's Learn About MCP Together

https://medium.com/womenintechnology/lets-learn-about-mcp-together-be1601dc7a81
2•mooreds•58m ago•0 comments

Higher education is shockingly right-wing

https://drafts.interfluidity.com/2023/03/01/higher-education-is-shockingly-right-wing/index.html
9•corimaith•1h ago•10 comments

Photographing a City That Stopped Changing: A Decade of Suburban Decay

https://aboutphotography.blog/blog/ghost-world-by-juan-rodrguez-morales
2•ChompChomp•1h ago•0 comments

Show HN: I built an AI that helps you chat with and visualize your codebase

https://www.thesuperfriend.com/
1•hez2000•1h ago•0 comments

University of Michigan using undercover investigators to surveil Gaza protestors

https://www.theguardian.com/us-news/2025/jun/06/michigan-university-gaza-surveillance
12•cempaka•1h ago•0 comments

Food additive titanium dioxide likely has more toxic effects than thought

https://www.theguardian.com/us-news/2025/jun/06/titanium-dioxide-food-additive-toxic
8•Jimmc414•1h ago•0 comments

I Built an AI Agent with Gmail Access and Discovered a Security Hole

2•Ada-Ihueze•1h ago•1 comments