Code Monkey home page Code Monkey logo

rest_api_demo's Introduction

rest_api_demo's People

Contributors

kleinerkobold avatar postrational avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rest_api_demo's Issues

License

Could you please add a license? Preferably MIT or similar? I'd love to be able to simply grab this and go for new projects, but for a variety of reasons, I can't do that without a license in place.

cannot import name 'cached_property' from 'werkzeug'

Get an error like this don't know what todo. Any idea ?

Traceback (most recent call last):
File "rest_api_demo/app.py", line 6, in
from rest_api_demo.api.blog.endpoints.posts import ns as blog_posts_namespace
File "/home/abdulsamed/temp/rest_api_demo/rest_api_demo/api/blog/endpoints/posts.py", line 4, in
from flask_restplus import Resource
File "/home/abdulsamed/.local/share/virtualenvs/rest_api_demo-ypuNYSIq/lib/python3.8/site-packages/flask_restplus/init.py", line 4, in
from . import fields, reqparse, apidoc, inputs, cors
File "/home/abdulsamed/.local/share/virtualenvs/rest_api_demo-ypuNYSIq/lib/python3.8/site-packages/flask_restplus/fields.py", line 17, in
from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (/home/abdulsamed/.local/share/virtualenvs/rest_api_demo-ypuNYSIq/lib/python3.8/site-packages/werkzeug/init.py)

Can not run the demo app

I follow the steps in this article to setup demo application, but there is an error raised.
Traceback (most recent call last):
File "rest_api_demo/app.py", line 6, in
from rest_api_demo.api.blog.endpoints.posts import ns as blog_posts_namespace
File "d:\workspace\rest_api_demo\rest_api_demo\api\blog\endpoints\posts.py", line 4, in
from flask_restplus import Resource
File "D:\workspace\rest_api_demo.venv\lib\site-packages\flask_restplus_init_.py", line 4, in
from . import fields, reqparse, apidoc, inputs, cors
File "D:\workspace\rest_api_demo.venv\lib\site-packages\flask_restplus\fields.py", line 12, in
from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (D:\workspace\rest_api_demo.venv\lib\site-packages\werkzeug_init_.py)

article: http://michal.karzynski.pl/blog/2016/06/19/building-beautiful-restful-apis-using-flask-swagger-ui-flask-restplus/

After investigation,
This error can be fixed by downgrading Werkzeug to version 0.16.0.

requirements.txt (before downgrading)
flask-restplus==0.9.2
Flask-SQLAlchemy==2.1

requirements.txt (after downgrading)
flask-restplus==0.9.2
Flask-SQLAlchemy==2.1
Werkzeug==0.16.0

Unit tests issue

When writing unittest,
from app import app
test_app = app.test_client()

but initialize_app and other functions not working.
How we can write unittest for your architecture.

Swagger 2.0 Schema validation errors

The generated Swagger schema fails validation. (Attached a copy as swagger.yaml for reference)

Putting http://localhost:8888/api/swagger.json into http://editor.swagger.io/ generates these errors:

Errors

 Semantic error at paths./blog/posts/archive/{year}/{month}/.get.operationId
operationIds must be unique
- Semantic error at paths./blog/posts/archive/{year}/{month}/{day}/.get.operationId
operationIds must be unique
- Schema error at responses.NoResultFound
requires property "description"

swagger_spec_validator, used by other swagger tools, only seems to fails on this exception:

import swagger_spec_validator
swagger_spec_validator.validate_spec_url('http://localhost:8888/api/swagger.json')

raises exception:

SwaggerValidationError: 'description' is a required property
...
On instance['responses']['NoResultFound']:

swagger.yaml.txt

deployed

Hi, Thank you for program, but i have a problem, i want to deploy in server but i am not sure what configuration i to do, can you help please.

List of values on api.inherit doesn't appear

Hi! I'm following this tutorial but I have a problem with the API pagination. Although the pagination data is appearing, the data fields don't. Do you have any idea what I can do?

My code:

flatdata_fields = api.model('Mutations', {
    'id': fields.Integer(readOnly=True),
    'mutation_code': fields.String(required=True),
    'pdb_mutant': fields.String,
    'pdbs_template': fields.String,
    'mutated_chain': fields.String,
    'mutation_type': fields.String,
    'mut_count': fields.Integer,
})
pagination = api.model('A page of results', {
    'total': fields.Integer(),
    'page': fields.Integer(),
    'per_page': fields.Integer(),
})

page_of_flatdata = api.inherit('Page of Mutation data', pagination, {
    'rows': fields.List(fields.Nested(flatdata_fields))
})
@td.route('/')
class rawThermDataList(Resource):
    @api.expect(pagination_arguments)
    @api.marshal_with(page_of_flatdata)
    def get(self):
        args = pagination_arguments.parse_args(request)
        page = args.get('page', 1)
        per_page = args.get('per_page', 10)
        return FlatData.query.paginate(page, per_page, error_out=False)

Thank you!

access db error since info.database can't be set

refer to: https://stackoverflow.com/questions/66647787/attributeerror-cant-set-attribute-when-connecting-to-sqlite-database-with-flas

sqlalchemy version should be set as 1.3.x, rather than 1.4.x by default now

(venv) wuwenxiangs-MacBook-Pro:rest_api_demo wuwenxiang$ python rest_api_demo/app.py
2021-08-11 05:56:50,154 - main - INFO - >>>>> Starting development server at http://localhost:8888/api/ <<<<<

  • Serving Flask app "app" (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: on
    2021-08-11 05:56:50,161 - werkzeug - INFO - * Running on http://localhost:8888/ (Press CTRL+C to quit)
    2021-08-11 05:56:50,162 - werkzeug - INFO - * Restarting with stat
    2021-08-11 05:56:50,510 - main - INFO - >>>>> Starting development server at http://localhost:8888/api/ <<<<<
    2021-08-11 05:56:50,514 - werkzeug - WARNING - * Debugger is active!
    2021-08-11 05:56:50,519 - werkzeug - INFO - * Debugger PIN: 228-831-182
    2021-08-11 05:57:09,343 - werkzeug - INFO - 127.0.0.1 - - [11/Aug/2021 05:57:09] "GET /api/ HTTP/1.1" 200 -
    2021-08-11 05:57:09,498 - werkzeug - INFO - 127.0.0.1 - - [11/Aug/2021 05:57:09] "GET /api/swagger.json HTTP/1.1" 200 -
    2021-08-11 05:57:15,325 - rest_api_demo.api.restplus - ERROR - An unhandled exception occurred.
    Traceback (most recent call last):
    File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/sqlalchemy/util/_collections.py", line 1008, in call
    return self.registry[key]
    KeyError: <greenlet.greenlet object at 0x1050b4d50 (otid=0x10507ebc0) current active started main>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_restplus/api.py", line 309, in wrapper
resp = resource(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_restplus/marshalling.py", line 101, in wrapper
resp = f(*args, **kwargs)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/rest_api_demo/api/blog/endpoints/categories.py", line 23, in get
categories = Category.query.all()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 500, in get
return type.query_class(mapper, session=self.sa.session())
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/sqlalchemy/orm/scoping.py", line 47, in call
return self.registry()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/sqlalchemy/util/_collections.py", line 1010, in call
return self.registry.setdefault(key, self.createfunc())
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 771, in create_session
return SignallingSession(self, **options)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 155, in init
bind = options.pop('bind', None) or db.engine
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 893, in engine
return self.get_engine(self.get_app())
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 910, in get_engine
return connector.get_engine()
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 542, in get_engine
self._sa.apply_driver_hacks(self._app, info, options)
File "/Users/wuwenxiang/local/github-mine/rest_api_demo/venv/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 877, in apply_driver_hacks
info.database = os.path.join(app.root_path, info.database)
AttributeError: can't set attribute
2021-08-11 05:57:15,328 - rest_api_demo.api.restplus - ERROR - An unhandled exception occurred.

ModuleNotFoundError

Hello,
I wanted to run your sample code, but apparently I can't import the root packet.

louis@Idris:~/git/rest_api_demo/rest_api_demo$ python3 app.py 
Traceback (most recent call last):
  File "app.py", line 4, in <module>
    from rest_api_demo import settings
ModuleNotFoundError: No module named 'rest_api_demo'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.