RestAPI various fixes

Hi Sarah, I've fixed SQL-injection and null-exception for domain lookup.
Note: I've merged the current master into this branch, otherwise the server will not function.