use singular and Capitalize. 's' will be added by the tool.
example: Car , Book, Order
Generate
Generate a new one
from flask import Flask, json,jsonify,request from flask_sqlalchemy import SQLAlchemy from marshmallow import Schema,fields app=Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"]='postgresql://dbuser:dbpassword@localhost/dbname' app.config["SQLALCHEMY_TRACK_MODIFICATIONS"]=False db=SQLAlchemy(app) # id #name #description class {{token_s_name}}(db.Model): id=db.Column(db.Integer(),primary_key=True) name=db.Column(db.String(255),nullable=False) description=db.Column(db.Text(),nullable=False) def __repr__(self): return self.name @classmethod def get_all(cls): return cls.query.all() @classmethod def get_by_id(cls,id): return cls.query.get_or_404(id) def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit() class {{token_s_name}}Schema(Schema): id=fields.Integer() name=fields.String() description=fields.String() @app.route('/{{token_lower_pl_name}}',methods=['GET']) def get_all_{{token_lower_pl_name}}(): {{token_lower_pl_name}}={{token_s_name}}.get_all() serializer={{token_s_name}}Schema(many=True) data=serializer.dump({{token_lower_pl_name}}) return jsonify( data ) @app.route('/{{token_lower_pl_name}}',methods=['POST']) def create_a_{{token_lower_s_name}}(): data=request.get_json() new_{{token_lower_s_name}}={{token_s_name}}( name=data.get('name'), description=data.get('description') ) new_{{token_s_name}}.save() serializer={{token_s_name}}Schema() data=serializer.dump(new_{{token_lower_s_name}}) return jsonify( data ),201 @app.route('/{{token_lower_s_name}}/',methods=['GET']) def get_{{token_lower_s_name}}(id): {{token_lower_s_name}}={{token_s_name}}.get_by_id(id) serializer={{token_s_name}}Schema() data=serializer.dump({{token_lower_s_name}}) return jsonify( data ),200 @app.route('/{{token_lower_s_name}}/',methods=['PUT']) def update_{{token_lower_s_name}}(id): {{token_lower_s_name}}_to_update={{token_s_name}}.get_by_id(id) data=request.get_json() {{token_lower_s_name}}_to_update.name=data.get('name') {{token_lower_s_name}}_to_update.description=data.get('description') db.session.commit() serializer={{token_s_name}}Schema() {{token_lower_s_name}}_data=serializer.dump({{token_lower_s_name}}_to_update) return jsonify({{token_lower_s_name}}_data),200 @app.route('/{{token_lower_s_name}}/',methods=['DELETE']) def delete_{{token_lower_s_name}}(id): {{token_lower_s_name}}_to_delete={{token_s_name}}.get_by_id(id) {{token_lower_s_name}}_to_delete.delete() return jsonify({"message":"Deleted"}),204 @app.errorhandler(404) def not_found(error): return jsonify({"message":"Resource not found"}),404 @app.errorhandler(500) def internal_server(error): return jsonify({"message":"There is a problem"}),500 if __name__ == '__main__': app.run(debug=True)