update api, add middleware and update examples