Implement getting data using rest api
This commit is contained in:
parent
b01aa43f32
commit
4e85d9e33a
@ -86,3 +86,40 @@ Add User:-
|
|||||||
This will give a response status 200 with no data if login is done.
|
This will give a response status 200 with no data if login is done.
|
||||||
This will return a 403 if the user gave wrong name or password.
|
This will return a 403 if the user gave wrong name or password.
|
||||||
_____________________
|
_____________________
|
||||||
|
|
||||||
|
|
||||||
|
_____________________
|
||||||
|
Get Data:-
|
||||||
|
URL:- /get_data
|
||||||
|
|
||||||
|
Method:- POST
|
||||||
|
|
||||||
|
Data:- None
|
||||||
|
|
||||||
|
Response:-
|
||||||
|
200 OK:-
|
||||||
|
Data:- All user data
|
||||||
|
Note:-
|
||||||
|
data:- {
|
||||||
|
entry_name: {
|
||||||
|
field_name: field_value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
403 Forbidden:-
|
||||||
|
Data:- Text that can be directly displayed to the user
|
||||||
|
Note:- Not logged in
|
||||||
|
|
||||||
|
|
||||||
|
Example:-
|
||||||
|
{
|
||||||
|
"Amazon": {
|
||||||
|
"Username": "Kosh",
|
||||||
|
"Password": "Pass1234"
|
||||||
|
},
|
||||||
|
"Matrix": {
|
||||||
|
"Username": "Kosh",
|
||||||
|
"Email": "kosh@fake.com",
|
||||||
|
"id": "@kosh:matrix.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_____________________
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from os import mkdir, path
|
from os import mkdir, path
|
||||||
from flask import Flask, request, send_file, abort, Response
|
from flask import Flask, request, send_file, abort, Response
|
||||||
from werkzeug.datastructures import ImmutableMultiDict
|
from werkzeug.datastructures import ImmutableMultiDict
|
||||||
|
|
||||||
from data_handler import DataHandler
|
|
||||||
import appdirs
|
import appdirs
|
||||||
|
import json
|
||||||
|
from data_handler import DataHandler
|
||||||
|
|
||||||
|
|
||||||
app: Flask = Flask(__name__)
|
app: Flask = Flask(__name__)
|
||||||
@ -39,7 +39,7 @@ class QueryHandler:
|
|||||||
"""
|
"""
|
||||||
This is the bridge between the frontend and DataHandler class
|
This is the bridge between the frontend and DataHandler class
|
||||||
"""
|
"""
|
||||||
__data_handler: DataHandler
|
__data_handler: DataHandler| None = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@app.post("/login")
|
@app.post("/login")
|
||||||
@ -104,6 +104,24 @@ class QueryHandler:
|
|||||||
|
|
||||||
return Response(status=200)
|
return Response(status=200)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@app.post("/get_data")
|
||||||
|
def get_data() -> Response:
|
||||||
|
"""
|
||||||
|
Return all user data
|
||||||
|
"""
|
||||||
|
if QueryHandler.__data_handler is None:
|
||||||
|
return Response(
|
||||||
|
"Not logged in",
|
||||||
|
403,
|
||||||
|
content_type="text/plain"
|
||||||
|
)
|
||||||
|
return Response(
|
||||||
|
json.dumps(QueryHandler.__data_handler.get_data()),
|
||||||
|
200,
|
||||||
|
content_type="application/json"
|
||||||
|
)
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user