File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -37,17 +37,20 @@ A minimal API
3737 # Create the Flask application and the Flask-SQLAlchemy object.
3838 app = Flask(__name__ )
3939 app.config[' DEBUG' ] = True
40- app.config[' SQLALCHEMY_DATABASE_URI' ] = ' sqlite:////tmp/test .db'
40+ app.config[' SQLALCHEMY_DATABASE_URI' ] = ' sqlite:////tmp/api_minimal .db'
4141 db = SQLAlchemy(app)
4242
43+
4344 # Create model
4445 class Person (db .Model ):
4546 id = db.Column(db.Integer, primary_key = True )
4647 name = db.Column(db.String)
4748
49+
4850 # Create the database.
4951 db.create_all()
5052
53+
5154 # Create schema
5255 class PersonSchema (Schema ):
5356 class Meta :
@@ -57,18 +60,25 @@ A minimal API
5760 self_view_many = ' person_list'
5861
5962 id = fields.Integer(as_string = True , dump_only = True )
60- name = fields.Str()
63+ name = fields.String()
64+
6165
6266 # Create resource managers
6367 class PersonList (ResourceList ):
6468 schema = PersonSchema
65- data_layer = {' session' : db.session,
66- ' model' : Person}
69+ data_layer = {
70+ ' session' : db.session,
71+ ' model' : Person,
72+ }
73+
6774
6875 class PersonDetail (ResourceDetail ):
6976 schema = PersonSchema
70- data_layer = {' session' : db.session,
71- ' model' : Person}
77+ data_layer = {
78+ ' session' : db.session,
79+ ' model' : Person,
80+ }
81+
7282
7383 # Create the API object
7484 api = Api(app)
@@ -79,6 +89,7 @@ A minimal API
7989 if __name__ == ' __main__' :
8090 app.run()
8191
92+
8293 This example provides the following API structure:
8394
8495======================== ====== ============= ===========================
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class Meta:
3030 self_view_many = 'person_list'
3131
3232 id = fields .Integer (as_string = True , dump_only = True )
33- name = fields .Str ()
33+ name = fields .String ()
3434
3535
3636# Create resource managers
You can’t perform that action at this time.
0 commit comments