This plugin helps you to make WordPress REST endpoints in a simpler and cleaner way.
Go to your WordPress plugin folder and clone this repo.
git clone [email protected]:suomato/simpler-rest-router.git
- Activate 
Simpler Rest Routerplugin. - Copy and paste code from 
_boilerplate.phpto yourfunction.phpfile. - Define your route. (Docs are included with boilerplate).
 
If you want better and cleaner code structure, define your route in a separate file and require that file in
functions.phpfile.