class_docstr: Dispatches request methods to the corresponding instance methods.
  For example, if you implement a ``get`` method, it will be used to
  handle ``GET`` requests.
  
  This can be useful for defining a REST API.
  
  :attr:`methods` is automatically set based on the methods defined on
  the class.
  
  See :doc:`views` for a detailed guide.
  
  .. code-block:: python
  
      class CounterAPI(MethodView):
          def get(self):
              return str(session.get("counter", 0))
  
          def post(self):
              session["counter"] = session.get("counter", 0) + 1
              return redirect(url_for("counter"))
  
      app.add_url_rule(
          "/counter", view_func=CounterAPI.as_view("counter")
      )
class_docstr_tok: ["Dispatches","request","methods","to","the","corresponding","instance","methods",".","For","example",",","if","you","implement","a","``","get","``","method",",","it","will","be","used","to","handle","``","GET","``","requests",".","This","can","be","useful","for","defining","a","REST","API",".",":","attr",":","`","methods","`","is","automatically","set","based","on","the","methods","defined","on","the","class",".","See",":","doc",":","`","views","`","for","a","detailed","guide",".","..","code-block",":",":","python","class","CounterAPI","(","MethodView",")",":","def","get","(","self",")",":","return","str","(","session.get","(","``","counter","''",",","0",")",")","def","post","(","self",")",":","session","[","``","counter","''","]","=","session.get","(","``","counter","''",",","0",")","+","1","return","redirect","(","url_for","(","``","counter","''",")",")","app.add_url_rule","(","``","\/counter","''",",","view_func=CounterAPI.as_view","(","``","counter","''",")",")"]
code: def dispatch_request(self, **kwargs: t.Any) -> ft.ResponseReturnValue:
      meth = getattr(self, request.method.lower(), None)
  
      # If the request method is HEAD and we don't have a handler for it
      # retry with GET.
      if meth is None and request.method == "HEAD":
          meth = getattr(self, "get", None)
  
      assert (
          meth is not None
      ), f"Unimplemented method {request.method!r}"
      return current_app.ensure_sync(meth)(**kwargs)
  
file_path: flask/src/flask/views.py
imports: from __future__ import annotations
  import typing
  from .None import typing
  from .globals import current_app
  from .globals import request
label_desc: Use image node_id 2 for calling the MethodView obj's underlying member method code with example usage: obj.dispatch_request() and returns: current_app