The first example is just that. Put the id in the URL and make the slug optional.
Stackoverflow makes the slug completely optional but you have the choice of only accepting foo and bar in your example
Stackoverflow makes the slug completely optional but you have the choice of only accepting foo and bar in your example
Not to mention something similar can be done to any url, e.g. #whatever-you-want or ?_=whatever-you-want