It's pretty straightforward.
frontend main-frontend
mode http
bind :80
use_backend foo-backend if { path_beg /foo }
use_backend bar-backend if { path_beg /bar }
Then you'd need to declare 2 backends, named "foo-backend" and "bar-backend" pointing to the servers and ports where those apps are listening (could be different servers, or just different ports on the same back-end servers). The names of the backends don't have to have "foo" and "bar" in them, as long as they match the names in the "use_backend" statements.
With this setup, the back-end servers need to be expecting the /foo or /bar at the beginning of the incoming path, because the entire request-path will be forwarded.
It is possible for haproxy to rewrite the path to scrub those out, but that configuration is rather more advanced.