code: def dispatch_request(self, *args, **kwargs):
          
          method = getattr(self, request.method.lower(), None)
          if method is None and request.method == 'HEAD':
              method = getattr(self, 'get', None)
          assert method is not None, 'Unimplemented method {}'.format(request.method)
  
          headers = {'Content-Type': 'application/vnd.api+json'}
  
          response = method(*args, **kwargs)
  
          if isinstance(response, Response):
              response.headers.add('Content-Type', 'application/vnd.api+json')
              return response
  
          if not isinstance(response, tuple):
              if isinstance(response, dict):
                  response.update({'jsonapi': {'version': '1.0'}})
              return make_response(json.dumps(response, cls=JSONEncoder), 200, headers)
  
          try:
              data, status_code, headers = response
              headers.update({'Content-Type': 'application/vnd.api+json'})
          except ValueError:
              pass
  
          try:
              data, status_code = response
          except ValueError:
              pass
  
          if isinstance(data, dict):
              data.update({'jsonapi': {'version': '1.0'}})
  
          return make_response(json.dumps(data, cls=JSONEncoder), status_code, headers)
docs: Logic of how to handle a request