Usually, I let the players level up their characters during a long rest. This implies the characters are in a safe (enough) space, and they start a new adventuring day fully rested and with their new abilities from the level-up. Sometimes, however, it makes sense to level up characters without a long rest.
The characters might have completed a significant milestone, warranting a level-up, but they might be in the middle of a dungeon. Or it’s just been too long without a level-up so that we want to give the players a level but they’re not in a position to long rest.
There’s a simple rule to allow levelling up without a long rest.
Characters gain any resources from the level-up but expended resources stay expended.
That means a character gains the maximum HP increase but their current hit points don’t increase. They gain new spell slots and spells but their expended spell slots stay expended. A battlemaster fighter gains another superiority die but their expended superiority dice stay expended.
This simple rule allows us to grant the characters a level-up without a long rest. It gives the characters new resources while expended resources stay expended.