This repository is the implementation of API for create, modify, delete and update of entry in text file
-
serve.py file contains the code of the http-server.
-
.env file contains what changes need to be made initially i.e., initial setup.
-
file_store.txt contains the data.
- IP: This field is the IP address. By default, it takes localhost as IP.
- PORT: This field is the PORT. By default, it takes 7000 as PORT.
-
After setting up the .env file, execute serve.py by
$ python3 serve.py
. It will show "Server started Successfully!" on successful execution. -
Now, Open the browser and type the API on the URL.
The different libraries in Python3 :
- http
- urllib
- re
- decouple
-
http://localhost:7000/file_store.txt?action=list To list the data stored in the file_store.txt file. On success, it returns 200 and the data present in the file. If no string is present against the id, it means that there is no data.
-
http://localhost:7000/file_store.txt?action=view&id={num} To view the data from the file where id = given num (without curly bracket). On success, it returns 200 and the data against the given id if the data is present otherwise "No Data Found!".
-
http://localhost:7000/file_store.txt?action=delete&id={num} To delete the data from the file where id = given num (without curly bracket). On success, it returns 200 and "OK".
-
http://localhost:7000/file_store.txt?action=create&string={string} To create the data in the file with string = given string (without curly bracket). On success, it returns 200 and "OK".
-
http://localhost:7000/file_store.txt?action=update&id={num}&string={string} To update/edit the data present in the file with string = given string (without curly bracket) where id = given num (without curly bracket). On success, it returns 200 and "OK".
- If no API matches, it returns 404 and "URL Not Found!".
The Entries in the file should follow the following format:
1:string1
2:string2