This is a Readme
file, every repository will have one, it explains details about the repository, about the technologies used in it, as well as details about the service and the API it has to communicate with the outside world.
- Make sure you have Python 3 installed
- Create a Python virtual environment by running:
python -m venv env
- Activate the virtual environment:
source env/bin/activate
- Install the libraries needed:
pip install -r requirements.txt
- Run the server locally:
sh run.sh
To view the requests the server allows, go to http://127.0.0.1:8000/docs
after you run the server.
There you will see all of the available requests and you can try them out.
- The server has the following endpoints:
GET
:/
--> which returns the message "Hello World"GET
:/users
--> This returns a map with our fake usersGET
:/user/{id}
--> This returns a specific users from our map based on theid
: To use it you need to send anid
in the GET request:users/1
If theid
exists you will get their details:If it does not exist, you will get the following:{ "name": "John Doe", "age": 25 }
{ "message": "Not found", "code": 404 }
POST
:/users/{id}
--> This request adds a user to our map: To use it, you need to send anid
in the URL like:users/4
Then also send a request body in the following structure:{ "name": "Jane Doe", "age": 25 }
DELETE
:/users/{id}
--> This deletes a user with a specificid
: To use it you need to send anid
for the user you want to delete, as well as thepassword
: The url would be:/users/1
and the body of the request would be:{ "password": "123" }
- The password is
1234
you can see it in the code. - Our map initially when running the service starts with the following values:
{
"1": { "name": "John Doe", "age": 25 },
"2": { "name": "Elizabeth Windsor", "age": 90 }
}