refactor into http api