- Make the file config.json in root folder with following parameters. (Sample given)
Admin User and Password is used to authorize the requests.
{ "MONGO_HOST": "mongo-atlas.mongodb.net", "USERNAME": "<username>", "PASSWORD": "<password>", "DATABASE": "<db_name>", "COLLECTION": "<collection_in_db>", "ADMIN_USER": "<Admin User>", "ADMIN_PASSWORD": "<Admin Password>" }
- Run
to start the web server.
python webservice.py
-
Headers required:
- Authorization:
<JWT Token>
- Authorization:
-
GET /
- DESCRIPTION: Healthy Point to verify
-
GET /authorize/
<username>
/<password>
- DESCRIPTION: Get auth token for creating requests.
- Returns JWT Token.
-
GET /getContacts/
<offset>
/<limit>
/?<query_params>
- DESCRIPTION: Fetch the list of contacts based on parameters specified.
- offset (optional) : Starting point from where the list should be displayed. (Default: 0)
- limit (optional. If given, offset is required as well.): Total number of items to display. (Default: 10)
- query_params: Search params to give. For example, /?email=[email protected]&phone=1111111111 etc. For example,
GET getContacts/[email protected] GET /getContacts/0/[email protected] GET /getContacts/0/2/[email protected]
- Returns JSON list of objects.
-
POST /createContact
- DESCRIPTION: Create new contact. Throws error if the any contact with same Email ID is already present.
- Request Body: Data to send.
{ "email": "[email protected]", "name": "qwerty", "phone": "1111111111" }
- Returns Object ID or error.
-
PUT /updateContact/
<id>
- DESCRIPTION: Update existing contact.
- Request Body: Data to send.
Other fields if given are automatically rejected. Basic validations for Email, Name and Phone number is also present. If invalid data, it throws error.
{ "email": "[email protected]", "name": "qwerty", "phone": "1111111111" }
- id: Object ID to update.
-
DELETE /deleteContact/
<id>
- DESCRIPTION: Delete existing contact.
- id: Object ID to delete.