Add API factory and tests