Giter Site home page Giter Site logo

app-generator / api-server-flask Goto Github PK

View Code? Open in Web Editor NEW
95.0 5.0 34.0 60 KB

Flask API Server - Open-Source API Server | AppSeed

Home Page: https://appseed.us/boilerplate-code/

License: Other

Python 98.15% Dockerfile 1.85%
flask api-server appseed-sample flask-api flask-restapi flask-restx open-source-api flask-api-sample flask-template free-api

api-server-flask's Introduction

Research and Innovation-oriented StartUp for Developers and Companies - Used by 8k+ registered Users.

Read more about the team, get support, or order a custom development sprint for MVPs and fully coded services.


AppSeed is a platform that uses in-house developed automation tools to cut the manual work usually involved in web development.

The App Generator is an automated workflow that consumes flat, lifeless UI Kits and builds starters in different patterns and languages: MVC, two-tier architecture, full-stack,SPA ..etc.

๐Ÿ‘‰ Read the full story published on Medium

The product is self-funded, mainly driven by open-source and community members connected to the service via different funnels (Email, Newsletter) and Discord (2k+ members).


AppSeed - Automation platform for developers.


Services and Products


Rocket Django Tailwind

The Django boilerplate has all you need to build your SaaS, Analytics tool, or any other type of Web App. From idea to production in 5 minutes.

Features: Django โ€ข Tailwind โ€ข API (DRF) โ€ข Celery Beat โ€ข DataTables โ€ข Charts โ€ข Docker โ€ข CI/CD.


Free Version PRO Version Custom Development
โœ“ Django 4.2.9 Everything in Free, plus: Everything in PRO, plus:
โœ“ Best Practices โœ… OAuth Google, GitHub โœ… 1mo Custom Development
โœ“ TailwindCSS/Flowbite โœ… Enhanced Charts โœ… Team: PM, Developer, Tester
โœ“ Extended User Model โœ… Enhanced DataTables โœ… Weekly Sprints
โœ“ Simple Charts โœ… Media Files Manager โœ… Technical SPECS
โœ“ Simple DataTables โœ… Stripe Payments โœ… Documentation
โœ“ API via DRF โœ… Wagtail CMS โœ… 30 days Delivery Warranty
โœ“ Celery Beat โœ… Multi-Language (i18n) Support -
โœ“ Docker โœ… Sentry Error Reporting -
โœ“ CI/CD Flow via Render โœ… PRO Support - Email & Discord -
โœ“ Free Support (GitHub Issues) โœ… Unlimited Projects -
- โœ… Private REPO Access -
- โœ… Lifetime Updates -
------------------------------------ ------------------------------------ ------------------------------------
๐Ÿš€ LIVE Demo ๐Ÿš€ LIVE Demo ๐Ÿ›’ Order: $3,999 (GUMROAD)

Free Django Dashboard and Admin Template - Rocket Django.



AppSeed - Research and Innovation-oriented StartUp for Developers and Companies

api-server-flask's People

Contributors

app-generator avatar ksh7 avatar mominur-helios 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

Watchers

 avatar  avatar  avatar  avatar  avatar

api-server-flask's Issues

Github OAuth - Runtime "json.decoder.JSONDecodeError"

Hello @mominur-helios

Ty for your work. I just tested the latest PR (merged into MAIN) and this is the status:

  • JWT Auth, no regression, feature works as before
  • OAuth via Github, not working.
    • In the UI the user gets: Network Error
    • In the backend: json.decoder.JSONDecodeError:

More details are below.
Please take a look. Ty!

React UI

image

Backend Runtime Err

127.0.0.1 - - [11/Dec/2022 09:28:00] "POST /api/users/login HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2022 09:28:02] "OPTIONS /api/users/logout HTTP/1.1" 200 -
  File "D:\work\repo-boilerplates\api-server-flask\env\lib\site-packages\flask\app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "D:\work\repo-boilerplates\api-server-flask\env\lib\site-packages\flask\app.py", line 1526, in full_dispatch_request
    return self.finalize_request(rv)
  File "D:\work\repo-boilerplates\api-server-flask\env\lib\site-packages\flask\app.py", line 1547, in finalize_request
    response = self.process_response(response)
  File "D:\work\repo-boilerplates\api-server-flask\env\lib\site-packages\flask\app.py", line 1889, in process_response
    response = self.ensure_sync(func)(response)
  File "D:\work\repo-boilerplates\api-server-flask\api\__init__.py", line 38, in after_request
    response_data = json.loads(response.get_data())
  File "C:\Python\Python310\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Python\Python310\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

`token_required` decorator does not work correctly on instance methods

The current_user is passed into the decorated function first, switching places with self:

return f(current_user, *args, **kwargs)

A possible fix would be to retain the first param in the inner decorator function:

def token_required(f):
    @wraps(f)
    def decorator(ref, *args, **kwargs):
         ...
         # call with ref
         return f(ref, current_user, *args, **kwargs)

But this will fail on regular functions. Probably inspect could be used to make it general.

Edit User - Does not return Authorization header

Same issue as pointed in Issue#8. I am running the dockerized version of the latest code.
Register -> OK
Login -> OK -> Shows the jwt token created value
Edit User -> Not OK -> Returns "success: false"

Response body

{
  "success": false,
  "msg": "Valid JWT token is missing"
}

Response headers:

access-control-allow-origin: http://localhost:5000 
 connection: keep-alive 
 content-length: 56 
 content-type: application/json 
 date: Thu,02 Jun 2022 05:45:50 GMT 
 server: nginx/1.21.6 
 vary: Origin 

Somehow the request is not sending back Authorization with token.
I am using swagger for API testing

Registration error - Internal Server Error

During the registration call, the server returns Error 500

Posman URL: http://localhost:5000/api/users/register

POST Request Body:

{
    "username":"test",
    "password":"pass", 
    "email":"[email protected]"
}

POSTMAN Response:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or
	there is an error in the application.</p>

Flask Log

PS D:\work\repo-api-servers\api-server-flask> flask run
 * Serving Flask app ".\run.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2021-07-14 15:49:31,974] ERROR in app: Exception on /api/users/register [POST]
Traceback (most recent call last):
  File "c:\python38\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\python38\lib\site-packages\flask\app.py", line 1953, in full_dispatch_request
    return self.finalize_request(rv)
  File "c:\python38\lib\site-packages\flask\app.py", line 1970, in finalize_request
    response = self.process_response(response)
  File "c:\python38\lib\site-packages\flask\app.py", line 2267, in process_response
    response = handler(response)
  File "D:\work\repo-api-servers\api-server-flask\api\__init__.py", line 33, in after_request
    response_data = json.loads(response.get_data())
  File "c:\python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "c:\python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "c:\python38\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[2021-07-14 15:49:31,982] ERROR in app: Request finalizing failed with an error while handling an error
Traceback (most recent call last):
  File "c:\python38\lib\site-packages\flask\app.py", line 1970, in finalize_request
    response = self.process_response(response)
  File "c:\python38\lib\site-packages\flask\app.py", line 2267, in process_response
    response = handler(response)
  File "D:\work\repo-api-servers\api-server-flask\api\__init__.py", line 33, in after_request
    response_data = json.loads(response.get_data())
  File "c:\python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "c:\python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "c:\python38\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
127.0.0.1 - - [14/Jul/2021 15:49:31] "POST /api/users/register HTTP/1.1" 500 -

Tests / Check Session - Expected I/O

API URL : http://localhost:5000/api/users/checkSession

Request Headers

  • Content-Type: application/json
  • authorization: JWT_TOKEN

Request Body - Empty

Response for success

{
    "success": true
}

Response for failure

{
    "success": false,
    "msg": "User is not logged on"
}

Register - Expected I/O

API URL : http://localhost:5000/api/users/register

Request Headers

  • Content-Type: application/json

Request Body

{
    "username":"test2",
    "password":"pass", 
    "email":"[email protected]"
}

Response

{
    "success": true,
    "userID": "60ef26c5f8b9f7294813f73d",
    "msg": "The user was succesfully registered"
}

Logout - Expected I/O

API URL : http://localhost:5000/api/users/logout

Request Headers

  • Content-Type: application/json
  • authorization: JWT_TOKEN_HERE

Request Body

{
    "token": "JWT_TOKEN_HERE"
}

Response For success

{
    "success": true,
    "msg": "Token revoked"
}

Response for unknown token

{
    "success": false,
    "msg": "User is not logged on"
}

Provide GET routes as well to return from database

If you could add GET routes, which actually pull/return data from DB (maybe user ID number?) on the default dashboard page, that would help tremendously; to extend to presenting other data on dashboard

Edit User - Expected I/O

API URL : http://localhost:5000/api/users/edit

Request Headers

  • Content-Type: application/json
  • authorization: JWT_TOKEN_HERE

Request Body

 {
        "userID": "60e81be0c625cd5d84390ebe",
        "username": "test_updated",
        "email": "[email protected]"
}

Response For success

{
    "success": true
}

Response for error (token inactive, mismatch userId / token)

{
    "success": false,
    "msg": "Error updating user"
}

The Response signature - Needs Update

The response signature should be in sync with the NodeJS version and POSTMAN definition.

The current structure returned by Login:

http://localhost:5000/api/users/login

{
    "errors": {
        "password": "'pass2' is too short"
    },
    "message": "Input payload validation failed"
}

Expected structure

{
    "success": false,
    "msg": "Wrong credentials"
}

The response info:

  • success: possible values true || false
  • msg: the first error that occurs during the request

Logout Action is not working

Logout action seems to have issues.

Test scenario:

  • Register New user
  • Login new user
    • token is generated
  • Use the generate token to logout

Current response

{
    "message": "The method is not allowed for the requested URL."
}

Expected Response

{
    "success": false,
    "msg": JWT Token revoked successfully"
}

Login - Expected I/O

API URL : http://localhost:5000/api/users/login

Request Headers

  • Content-Type: application/json

Request Body

{
    "password":"pass", 
    "email":"[email protected]"
}

Response

{
    "success": true,
    "token": "JWT_TOKEN_HERE",
    "user": {
        "_id": "1",
        "username": "test",
        "email": "[email protected]"
    }
}

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Hi ,

I added a simple route to the routes.py file

@rest_api.route('/hellos')
class TestProcedure(Resource):
	def get(self):
		hello =  {"hello": "test"}
		return jsonify(hello)

I also tried

@rest_api.route('/hellos')
class TestProcedure(Resource):
	def get(self):
		hello = "lol"
		return {"success": True}, 200

I always get this error i have to reload my page 2-3 times to get the actual result


Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2095, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2080, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.10/dist-packages/flask_restx/api.py", line 672, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1526, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1547, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1889, in process_response
    response = self.ensure_sync(func)(response)
  File "/home/malpwn/latest_build/app-generator/api-server-flask/api/__init__.py", line 50, in after_request
    response_data = json.loads(response.get_data())
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


Login - Success flag missing from the response

Symptom: The response comes with different variables:

  • success is missing
  • message (error info) instead of msg

Request URL: http://localhost:5000/api/users/login

Request body:

{
    "password":"pass2", 
    "email":"[email protected]"
}

Response

{
    "message": "Sorry. This email does not exist."
}

Expected Response

{
    "success": false,
    "msg": "Sorry. This email does not exist"
}

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.