Clients need a valid API_Key to access the API, and also valid JsonWebTokens for validating api calls after login.
So each HTTP request is expected to have following HEADERS
:
"X-API-Key" : *API_KEY* (mandatory) "x-access-token" : JWT_Token (only required when logged in) "Content-Type" : "application/json"
- NOTE : JWT is required for authorization of requests only after login
For SocketIO (if used) communication, the following extraHeaders
are required:
"x-access-token" : JWT_Token (mandatory)
Base API url : https://secrep.herokuapp.com/
Example endpoints to send requests:
Citizen app => https://secrep.herokuapp.com/signup
Patrol app => https://secrep.herokuapp.com/patrol/login
Admin app => https://secrep.herokuapp.com/admin/login
Prefix - NONE
-
POST
/signup
(Authenticate patrol and create JWT)
name required data type description user YES string Unique username password YES string N/A wallet_addr optional string Crypto wallet address http code response 201
{"user_exists":false, message:"User registered}
400
{"error": "Username and Password REQUIRED"}
409
{"message": "Username already taken","user_exists": true}
POST
/login
(Authenticates a user, returns JWT)
name required data type description user YES string Unique username password YES string N/A http code response 200
{"login": true, "user_exists": true, "token": str(JWT_token) }
400
{"error": "Username and Password REQUIRED"}
401
{"login": false,"user_exists": false}
401
{"message" : "Incorrect Password", "login": false,"user_exists": true}
POST
/change-wallet
(Modifies wallet address)
- Requires JWT in request HEADERS for authorization
name required data type description new_addr YES string New wallet address http code response 200
{"message": "Updated wallet address!" }
-
*** Requires JWT in request HEADERS for authorization
GET
/get-reports
(Returns IDs of reports lodged by the user)
None
http code response 200
{"cases": []}
- List of case IDsPOST
/new-report
(Creates/Lodges a report)
name required data type description desc YES string Detailed description of the case location YES string Location in text or latitude-longitude time YES Datetime object Approximate time type YES string Crime category; Type of crime offenders - string victims - string http code response 201
{"uploaded":"success", "user_cases":LIST_of_CaseIds}
404
{"error":"Cannot find the location specified!!"}
POST
/emergency
(Creates/Lodges an emergency situation)EXPERIMENTAL
This will create a case consuming location of report and finding the nearest 4 authorities
name required data type description location YES string Location in text or latitude-longitude http code response 201
{"nearest_authority":NearestAuthorityID, "nearest_authorities":LIST_of_NearestAuthorityIds}
404
{"error":"Cannot find the location specified!!"}
POST
/get-case-info
(Returns details of a particular case)
name required data type description case_id YES string Obtained from /get-reports http code response 200
CASE-OBJECT { "_id": case_id, "desc": desc, "victims": victims, "ofenders": ofenders, "location": None, "time": time, "crime_files": files, "crime_score": None, "classified_ByUser": classified_ByUser, "classified_model": None, "faces_bymodel": [], "Status": "Assigned", "authority_assigned": authority_assigned[0]["_id"] }
Prefix -
/patrol
-
POST
/login
(Authenticates patrol)
name required data type description PatrolID YES string Unique id of authority/Patrol password YES string N/A location YES string Current location of Patrol http code response 200
{"login": true, "token": JWT, "user_exists": true}
400
{"error": "No Data Payload!!"}
401
{"login": false, "user_exists": false}
401
{"login": false, "user_exists": true}
-
*** Requires JWT in request HEADERS for authorization
GET
/get-cases
(Retrieve assigned cases)
http code response 200
{"cases": LIST_of_CaseIds }
404
{"message": "unable to find user"}
POST
/get-case-info
(Returns details of a particular case)
name required data type description case_id YES string Obtained from /get-reports http code response 200
CASE-OBJECT { "_id": case_id, "desc": desc, "victims": victims, "ofenders": ofenders, "location": None, "time": time, "crime_files": files, "crime_score": None, "classified_ByUser": classified_ByUser, "classified_model": None, "faces_bymodel": [], "Status": "Assigned", "authority_assigned": authority_assigned[0]["_id"] }
POST
/case-status
(Update status of a case)
name required data type description case_id YES string ID of case to be updated status YES string new status for the case - insufficient
- Assigned
- Resolved
- Duplicate
- Unassigned
http code response 200
insufficient - {"msg":"Status Updated"}
200
Assigned - {"msg":"Status Updated"}
200
Resolved - {"transaction_hash": TXN_HASH }
200
Resolved - {"error": "unable to send cryptocurrency" }
204
Duplicate - {"msg":"Case removed"}
200
Unassigned - {"msg":"Status updated"}
404
{"error": "Trying to update status of unassigned case"}
400
{"error": "No Data Payload!!"}
Prefix -
/admin
-
POST
/login
(Authenticate admin)
name required data type description user YES string Unique admin id password YES string N/A http code response 200
{"login": true, "token": JWT, "user_exists": true}
400
{"error": "No Data payload!!"}
401
{"login": false, "user_exists": false}
401
{"login": false, "user_exists": true}
GET
/get-cases
(Retrieve cases)
*** JWT required in request HEADERS
http code response 200
{"cases" : LIST_of_all_Cases}
404
{"error": ERROR_MSG }
Sample case item:
{ "_id": case_id, "desc": desc, "victims": victims, "ofenders": ofenders, "location": None, "time": time, "crime_files": files, "crime_score": None, "classified_ByUser": classified_ByUser, "classified_model": None, "faces_bymodel": [], "Status": "Assigned", "wallet_addr": current_user["wallet_addr"], "authority_assigned": authority_assigned[0]["_id"] }
-
*** Requires JWT in request HEADERS for authorization
POST
/add-patrol
(Register patrol/authority/PoliceStation)
name required data type description PatrolID YES string Unique patrol id password YES string N/A location YES string In form of text or co-ordinates http code response 201
{"user_exists": false}
=> Successfully created409
{"user_exists": true}
=> Already exists, Conflict404
{"error":"Cannot find the location specified!!"}
400
{"error": "No Data payload!!"}
- Server-side has implementation of Socket.IO server API which is based and built on top of WebSocket Protocol
- To establish and communicate properly via sockets from the client-side,
it is recommended to use Socket.IO client helper libraries/API
Example: Socket.IO client API for JavaScript, Socket.IO client for Dart etc.
For more info and docs on Socket.IO, click here - To open a WebSocket connection with server from client, use the following urls to connect
- Admin -
https://secrep.herokuapp.com/admin
; namespace -/admin
- Patrol -
https://secrep.herokuapp.com/patrol
; namespace -/patrol
NOTE : The above urls are entirely different from traditional http urls and can't be accessed directly like http urls, instead they are called Socket.IO namespaces
- Admin -
- Checkout basic examples
Implement required events on the client-side documented below...
-
Admin events
Emitting events to server
Get_cases
- Fetch cases from DBGet_patrols
- Fetch patrol(s) and their assigned cases from DB
The above 2 events return static latest data from DB like http GET...
Why not useGET
?
If client already opened a socket connection, why not use socket communicationListening to events from server
PatrolUpdate
- Receive real-time assignments/unassignments of cases to patrolCaseUpdate
- Receive real-time updates whenever cases are added/removed/updated, doesn't matter if case is assigned or not, any CUD operation triggered will emit this event from serverstatic-cases
- In response toGet_cases
, this event returns all case objectsstatic-patrol
- In response toGet_patrols
, this event returns all patrol documents
-
Patrol events
Emitting events to server
Get_cases
- Fetch assigned cases from DB
Listening to events from server
CaseUpdate
- Receive real-time updates whenever cases are assigned/unassignedstatic-cases
- In response toGet_cases
, this event returns all assignedcase_ids