Package: chillapi
ChillApiMotivationThis project was born to increase the speed of delivery and development of APIs.The premise is simple, not all roles can feel comfortable swimming in a sea of indented code, however they do feel comfortable in SQL languages. And those who do feel comfortable programming may prefer to use a tool that configures and propagates information than extending an ORM, routes, forms, etc; thus being able to spend more time on other types of tasks.The connection and execution of queries is done in raw, that is, there is no ORM involved.The implementation of this framework is on Flask using a series of additional libraries and adopting others to satisfy the requirements of the same.setupCreate aapi.yamlfile:app:name:ChillApiversion:'0.1'swagger_url:'/swagger'swagger_ui_url:'/doc'host:0.0.0.0port:8000debug:True#  externalDocs:#    description: Find more info here#    url: https://example.com#  license:#    name: Apache 2.0#    url: https://www.apache.org/licenses/LICENSE-2.0.html#  contact:#    name: API Support#    url: http://www.example.com/support#    email: support@example.comsecuritySchemes:bearerAuth:# arbitrary name for the security schemetype:httpscheme:bearerbearerFormat:JWTsecurity:-bearerAuth:[]security_level:STANDARDsecurity_handler:package:my_app.authhandler:authenvironment:__CHILLAPI_DB_DSN__:'$DB_URL'#  __CHILLAPI_DB_DSN__: 'sqlite:///var/db.sqlite'__CHILLAPI_APP_SECRET_KEY__:'super-secret-key'logger:app:output:stdoutlevel:10audit_logger:output:stdoutlevel:40error_handler:output:stdoutlevel:40sqlalchemy:output:stdoutlevel:40database:schema:publicdefaults:tables:id_field:idfields_excluded:# silent check if exists in the tableall:-created_at-updated_by-updated_at-created_by-deleted_at-deleted_byGET:SINGLE:[]# request onlyLIST:[]# request onlyPOST:SINGLE:-idLIST:[]PUT:SINGLE:-idLIST:-idapi_endpoints:PUT:[SINGLE,LIST]GET:[SINGLE,LIST]POST:[SINGLE,LIST]DELETE:[SINGLE,LIST]extensions:audit_logger:package:my_app.audithandler:MyAuditHandlerhandler_args:name:hellosoft_delete:enable:Truedefault_field:deleted_aton_update_timestamp:enable:Truedefault_field:updated_aton_create_timestamp:enable:Truedefault_field:created_attables:-name:book_category#      alias: ~#      id_field: ~ # id by defaultextensions:soft_delete:cascade:one_to_many:-table:bookcolumn_id:idcolumn_fk:book_category_id-name:book#      alias: ~#      id_field: ~ # id by default#      extensions:#        soft_delete:#          enable: Falsefields_excluded:# extends defaults#        all: [ ]#        GET:#          SINGLE:#            - name#          LIST: [ ]POST:SINGLE:-isin#          LIST: [ ]#        PUT:#          SINGLE:#            - name#          LIST: [ ]#        DELETE:#          SINGLE: [ ]#          LIST: [ ]#      api_endpoints:   #overwrite defaults#        GET: [ SINGLE ]-name:author#      alias: ~#      id_field: isoextensions:after_response:package:my_app.default_eventshandler:MyAfterResponseEventbefore_response:package:my_app.default_eventshandler:MyBeforeResponseEventsoft_delete:cascade:many_to_many:-table:authorcolumn_id:idjoin_table:book_has_authorjoin_columns:main:author_idjoin:book_idvalidators:asin:-package:wtforms.validatorshandler:Lengthhandler_args:min:5max:100fields_excluded:#        all: []GET:SINGLE:-name#          LIST: [ ]#        POST:#          SINGLE: []#          LIST: [ ]#        PUT:#          SINGLE: []#          LIST: [ ]#        DELETE:#          SINGLE: [ ]#          LIST: [ ]api_endpoints:{}-name:dummy#      alias: ~#      id_field: ~extensions:soft_delete:enable:Falseon_update_timestamp:enable:Falseon_create_timestamp:enable:False#      fields_excluded:#        all: [ ]#        GET:#          SINGLE: [ ]#          LIST: [ ]#        POST:#          SINGLE: [ ]#          LIST: [ ]#        PUT:#          SINGLE: [ ]#          LIST: [ ]#        DELETE:#          SINGLE: [ ]#          LIST: [ ]api_endpoints:{}-name:dummy_create#      alias: ~#      id_field: ~extensions:soft_delete:enable:Falseon_update_timestamp:enable:Falseon_create_timestamp:enable:Truedefault_field:creation#      fields_excluded:#        all: [ ]#        GET:#          SINGLE: [ ]#          LIST: [ ]#        POST:#          SINGLE: [ ]#          LIST: [ ]#        PUT:#          SINGLE: [ ]#          LIST: [ ]#        DELETE:#          SINGLE: [ ]#          LIST: [ ]api_endpoints:GET:[SINGLE,LIST]sql:-name:testsmethod:GETurl:/tests/test_sqlsql:|select * from authorquery_parameters:[]# swagger schema for url query parameters in sqlresponse_schema:type:object#        parameters:#          test:#            type: string-name:tests 2method:GETurl:/tests/test_sql2sql:|select c.name as book_name, cr.*from book cinner join book_category cr ON cr.id = c.book_category_id AND c.name = :namequery_parameters:# swagger schema for url query parameters in sql-in:queryname:name#          required: trueschema:type:string-name:test_paramsmethod:POSTurl:/test_params_postsql:|select c.name as book_name, cr.*from book cinner join book_category cr ON cr.id = c.book_category_id AND c.name = :namerequest_schema:# swagger schema for url query parameters in sqltype:objectproperties:name:type:string#            required: truetemplates:-name:testsmethod:GETurl:/test_template# swagger route formattemplate:./api_sql_templates/test.sqlquery_parameters:[]# swagger schema for url query parameters in sql-name:test_paramsmethod:GETurl:/test_template_paramstemplate:./api_sql_templates/test_params.sqlquery_parameters:# swagger schema for url query parameters in sql-in:queryname:name#          required: trueschema:type:string-name:test_paramsmethod:GETurl:/test_template_params_url/<name>template:./api_sql_templates/test_params.sqlquery_parameters:# swagger schema for url query parameters in sql-in:pathname:namerequired:true#          schema:#            type: string-name:test_paramsmethod:POSTurl:/test_template_paramstemplate:./api_sql_templates/test_params.sqlrequest_schema:# swagger schema for url query parameters in sqltype:objectproperties:name:type:stringCreate your app.py filefromchillapi.apiimportChillApi_resources=ChillApi()app=_resources.appapi_config=_resources.api_configif__name__=='__main__':app.run(debug=api_config['app']['debug'],host=api_config['app']['host'],port=api_config['app']['port'])Run your apppythongunicorn--bind0.0.0.0:8000app:appThe internalsDatabaseThe milestone is support:Postgres [x]MySQL/MariDBSQLiteRedshiftDB connection and inspection is done using SQLAlchemySQL queries are made with:https://github.com/kayak/pypikaSpecial queriesThese queries are made to reduce the overhead in some cases such as a bulk delete where we validate if the ids provided are in our db firstsee:chillapi.database.repository._MAGIC_QUERIESEndpointsBased on the config file.Extends from:chillapi.swagger.http.AutomaticResourceTable typeAutomatically maps all the table and exposes all the columns.Exclusion byexcluded_fieldsconfigAs far this a direct map to the columns, the POST/PUT endpoints will require as request body these columns, and the response body will show that columns.DELETE and POST automatically attach the id the url, this field is mapper ti theid_fieldconfigSame way bulk operations will map theid_fieldconfig to the correspondent field in the request body.SQL TypeThis type of endpoint in the simplest case will throw a response with a json that contains the result of the SQl specified.In addition, you can use placeholders in your query and specify the proper swagger schema in the config.Template typeWorks in the same way that the SQL type, but you can specify a path to a template (larger sqls)setup developmentcd$PROJECT_DIRdocker-composeupmakerun_dev# or install by yourself the venv etc. You will need to have psycopg binary installedSeeMakefileOther optionshttps://github.com/dbohdan/automatic-api