In D&D 5e can I use my bonus action before my action? For example if I wanted to cast Ensnaring Strike before my action to benefit from the bonus immediately.
Is this OK, or is a bonus action intended to be used after the action?
The rule for bonus actions says:
You choose when to take a bonus action during your turn, unless the bonus action's timing is specified, and anything that deprives you of your ability to take actions also prevents you from taking a bonus action.
So unless the bonus action specifies that you have to take it at a specific time, you can take the bonus action at any point in your turn.
For an example of a bonus action which restricts the timing like this, check out the Monk's Flurry of Blows:
Immediately after you take the Attack action on your turn, you can spend 1 ki point to make two unarmed strikes as a bonus action.
In the case of Ensnaring Strike, neither it specifically nor bonus action spells in general place any restrictions on timing, so you can cast it at any point in your turn.