Depends on the project I guess. For projects with a defined scope and enough time and money, writing the API first is the way to go, because it enables clear code planning and it's easy to define priorities and see the overall progress of implemented pieces.
However, in real life, most of my projects are experiments. They start out with an idea: "We want to create Something™", and the problem is that we need financing, so we have to blast out the first PoC for the idea in only a couple of weeks. There simply is no time to think about the end-product and plan everything down to the last knob for the first release. That's why I mostly write code first, then generate a documentation from my comments. Hence I have the habit of writing long comments for methods and important classes, explaining what they do and sometimes how they work with other pieces. I even sometimes add examples. It's very agile, because we often have to change code, features or the entire scope, depending on politics and how the product develops and fits in with the stakeholders.