Add a 'request' function to API to wait for responses to commands.

Fixed #157.