title: How to create routes with FastAPI within a class
body: <p>So I need to have some routes inside a class, but the route methods need to have the <code>self</code> attr (to access the class' attributes).
  However, FastAPI then assumes <code>self</code> is its own required argument and puts it in as a query param</p>
  <p>This is what I've got:</p>
  <pre class="lang-py prettyprint-override"><code>app = FastAPI()
  class Foo:
      def __init__(y: int):
          self.x = y
  
      @app.get(&quot;/somewhere&quot;)
      def bar(self): return self.x
  </code></pre>
  <p>However, this returns <code>422</code> unless you go to <code>/somewhere?self=something</code>. The issue with this, is that <code>self</code> is then str, and thus useless.</p>
  <p>I need some way that I can still access <code>self</code> without having it as a required argument.</p>