refactoring js logic; adding get js method to query rest api