messages: refactoring and REST API 

Refactoring of the messages module. An api.py file has been created in order to interact with the database. Also a restful.py file has been created so that messages can have a REST API.
62:27: E111 indentation is not a multiple of four
62:27: E113 unexpected indentation
74: D290 White spaces around docstring should be trimmed.
79: D290 White spaces around docstring should be trimmed.
285: D290 White spaces around docstring should be trimmed.