Can I use a bonus action before my action?


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?