Prepare Blade Ward using the Ready Action
This is how it would work RAW:
You: I use the Ready Action to cast the Blade Ward cantrip. If someone attempts to attack me, I'll activate the spell. My turn is now over.
The obvious downside to this is that you cannot do this while also attacking normally on your turn. To my knowledge, there is no way, short of using Action Surge or the Quickened Spell metamagic, to both attack and Ready a spell (Blade Ward or otherwise) in the same turn. As a result, there's no real benefit to doing this: Blade Ward lasts until the beginning of your next turn anyways, so casting like this gives the same effect, while also consuming your Reaction, making you unable to use your Reaction for anything else.
Consider the spell Shield instead
The 1st level spell Shield seems more suited to what you're trying to do. Its effects are different than Blade Ward (Shield gives +5AC, whereas Blade Ward gives resistance to Physical Damage), but both have the effect of mitigating damage, and the difference with Shield is that it is explicitly cast using a casting time of 1 Reaction. So it's possible to attack in your turn and then still react by casting Shield, should you get attacked.