-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
59 additions
and
23 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from main import db | ||
|
||
class User(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
username = db.Column(db.String(80), unique=True, nullable=False) | ||
email = db.Column(db.String(80), unique=False, nullable=False) | ||
|
||
def __init__(self, username, email): | ||
self.username = username | ||
self.email = email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
aniso8601==9.0.1 | ||
blinker==1.6.2 | ||
certifi==2023.7.22 | ||
charset-normalizer==3.2.0 | ||
click==8.1.7 | ||
flask==2.3.3 | ||
Flask-RESTful==0.3.10 | ||
flask-sqlalchemy==3.1.1 | ||
greenlet==2.0.2 | ||
idna==3.4 | ||
importlib-metadata==6.8.0 | ||
itsdangerous==2.1.2 | ||
Jinja2==3.1.2 | ||
MarkupSafe==2.1.3 | ||
psycopg2==2.9.7 | ||
pytz==2023.3.post1 | ||
requests==2.31.0 | ||
six==1.16.0 | ||
SQLAlchemy==2.0.21 | ||
typing-extensions==4.8.0 | ||
urllib3==2.0.5 | ||
werkzeug==2.3.7 | ||
zipp==3.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import requests | ||
|
||
BASE = "http://127.0.0.1:5000/" | ||
|
||
response = requests.get(BASE + "user/3") | ||
print(response.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
from flask import Blueprint, jsonify, request | ||
from flask_restful import Resource, Api | ||
|
||
user_bp = Blueprint("user", __name__) | ||
userBP = Blueprint("user", __name__) | ||
|
||
|
||
listOfStudents = { | ||
"1": {"name": "Liam", "email": "email:"}, | ||
"2": {"name": "Daws", "email": "email:"}, | ||
"3": {"name": "Brem", "email": "email:"} | ||
} | ||
|
||
@user_bp.route("/createUser", methods=["POST"]) | ||
def createUser(): | ||
#route specific code | ||
class User(Resource): | ||
def get(self, id): | ||
return listOfStudents[id] | ||
|
||
|
||
data = request.get_json() | ||
return jsonify(data) | ||
def post(self, name, age): | ||
new_user = User(name=name, age=age) | ||
return {"data": "Posted"} | ||
|
||
|
||
|
||
#initialize the flask restful api using the blueprint | ||
api = Api(userBP) | ||
api.add_resource(User, "/user/<id>") |