title: Flask: Preferred way to manipulate view arguments?
body: <p>I'm creating REST API with Flask &amp; have a question related to manipulating the arguments of the view questions. I have currently two resources, "Survey" and "SurveyStep", accessible through:</p>
  
  <pre><code>/surveys
  /survey/*survey-id*/steps/*step-id*
  </code></pre>
  
  <p>Since I'll be using the Survey resource for each request, I want it to be fetched automatically (SQLAlchemy) before each request.</p>
  
  <p>Currently I found 3 ways to do this:</p>
  
  <p>1) Write a URL converter, as described in (<a href="http://corbinsimpson.com/entries/be-prepared.html" rel="nofollow">http://corbinsimpson.com/entries/be-prepared.html</a>)</p>
  
  <p>2) Use @....before_request, adding things to the request.view_args manually</p>
  
  <p>3) Use @....before_request, adding it to the flask.g object</p>
  
  <p>I first tried 1), which has the issue that the alchemy objects do not belong to the session, and in case of lazy relationships they need to be added first.</p>
  
  <p>2) seems "dirty", as your functions get arguments that aren't really visibly declared</p>
  
  <p>3) is what I'm using now, it makes the view arguments not needed in the functions itself, but it solves the session issue &amp; it's a bit more visible than 2.</p>
  
  <p>Any thoughts, caveats, improvements?</p>
  
  <p>Thanks!</p>