Refactor api spec, add checks for 404 status and json structure