Commit 5cabd47b authored by Caleb Connolly's avatar Caleb Connolly 💬

Making a proper API with real libs...

"python.pythonPath": "venv/bin/python3.7"
\ No newline at end of file
from flask_restful import Resource
from flask_restful import Resource, reqparse
user_parser = reqparse.RequestParser()
user_parser.add_argument('username', help = 'This field cannot be blank', required = True)
user_parser.add_argument('password', help = 'This field cannot be blank', required = True)
class UserRegistration(Resource):
def post(self):
data = user_parser.parse_args()
return data
class UserLogin(Resource):
def post(self):
return {'message': 'User login'}
class UserLogoutAccess(Resource):
def post(self):
return {'message': 'User logout'}
class UserLogoutRefresh(Resource):
def post(self):
return {'message': 'User logout'}
class TokenRefresh(Resource):
def post(self):
return {'message': 'Token refresh'}
class AllUsers(Resource):
def get(self):
return {'message': 'List of users'}
def delete(self):
return {'message': 'Delete all users'}
class SecretResource(Resource):
def get(self):
return {
'answer': 42
\ No newline at end of file
from flask import Flask
from flask_restful import Api
app = Flask(__name__)
api = Api(app)
API_ROOT = "/api/v1"
import views, models, resources
api.add_resource(resources.UserRegistration, f'{API_ROOT}/registration')
api.add_resource(resources.UserLogin, f'{API_ROOT}/login')
api.add_resource(resources.UserLogoutAccess, f'{API_ROOT}/logout/access')
api.add_resource(resources.UserLogoutRefresh, f'{API_ROOT}/logout/refresh')
api.add_resource(resources.TokenRefresh, f'{API_ROOT}/token/refresh')
api.add_resource(resources.AllUsers, f'{API_ROOT}/users')
api.add_resource(resources.SecretResource, f'{API_ROOT}/secret')
\ No newline at end of file
from run import app
from flask import jsonify
def index():
return jsonify({'message': 'Hello, World!'})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment