Python Flask failing on api.route('/')

Why does this simple code fail? I don't get it:

import sys
import pprint
import socket
from flask import Flask, request
from flask_restplus import Resource, Api
app = Flask(__name__)
api = Api(app)
@api.route('/')
class Root():
    def get(self):
        return { 'I am get.' }
    def post(self):
        return { 'I am post.' }

I've seen ...route('/') used in examples, like http://blog.luisrei.com/articles/flaskrest.html, but this is what I get:

Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51) 
[GCC 7.2.0] on linux
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/project/libdev_py/libmems_conda/envs/py36/lib/python3.6/site-packages/flask_restplus/namespace.py", line 92, in wrapper
    self.add_resource(cls, *urls, **kwargs)
  File "/project/libdev_py/libmems_conda/envs/py36/lib/python3.6/site-packages/flask_restplus/namespace.py", line 82, in add_resource
    api.register_resource(self, resource, *ns_urls, **kwargs)
  File "/project/libdev_py/libmems_conda/envs/py36/lib/python3.6/site-packages/flask_restplus/api.py", line 261, in register_resource
    self._register_view(self.app, resource, *urls, **kwargs)
  File "/project/libdev_py/libmems_conda/envs/py36/lib/python3.6/site-packages/flask_restplus/api.py", line 273, in _register_view
    previous_view_class = app.view_functions[endpoint].__dict__['view_class']
KeyError: 'view_class'
>>> 

1 answer