- Set up server for Local Machine
- DataBase Info
- Base Uri/Live Deployment
- Run API Tests
- UML Class Diagram
- Error Handling
- EndPoints
- Sample Usage
- Limitations or Assumptions
- Authors
Hosted for live testing on https://godand.pythonanywhere.com
....
$ git clone https://github.com/Godhanded/crudhng.git
$ cd crudhng
# create Virtual Environment
$ python3 -m venv venv
# Activate Virtual Env
$ source venv/bin/activate
# Install Dependencies
$ pip install -r requirements.txt
$ python3 run.py
Note: ensure you are connected to the internet before running tests and are in crudhng directory
# install test suite and http requests library
$ pip install requests pytest
# Run the tests in test_crud.py
$ pytest test_crud.py -v
- Sqlite file database is used
- SqlAlchemy ORM was used for db interactions
- Sqlite file.db file is created in
/instance
directory when the server is run for the first time. - DataBase Models click here
Errors are returned as JSON objects in the following format with their error code
{
"error": "error name",
"message": "error description"
}
The API will return 2 error types, with diffreent descriptions when requests fail;
- 404: resource not found
- 500: Internal server error
POST '/api'
- Creates a new user and adds them to DataBase
- Request Body: JSON object containing
{
"name":"name of person",
}
- Returns: JSON, Id and Name of created user
{
"message": "Success",
"id": 1,
"name": "name of person"
}
status code: 201
GET '/api/${id}'
- Gets a person from the database using user id
- Path Parameter:
id
- integer id of person to retrieve - Returns: JSON, message and person object containing name id and date created
{
"message": "Success",
"person": {
"id":1,
"name":"name of user",
"date_created":"Mon, 11 Sep 2023 01:04:27 GMT"
}
}
status code: 200
PATCH '/api/${id}'
- Update or change name of person record
- Path Parameter:
id
- integer id of person to update - Request Body: Json object containing
{
"name":"new name"
}
- Returns: JSON, message and person object containing name id and date created
{
"message": "name updated",
"id": 0,
"name":"new name"
}
status code: 200
PUT '/api/${id}'
- Update or change name of person record
- Path Parameter:
id
- integer id of person to update - Request Body: Json object containing
{
"name":"new name"
}
- Returns: JSON, message and person object containing name id and date created
{
"message": "name updated",
"id": 0,
"name":"new name"
}
status code: 200
DELETE '/api/${id}'
-
Delete record of Person from database
-
Path Parameter:
id
- integer id of person to delete -
Returns: JSON, message and id of deleted record
{
"message": "deleted",
"id": 3
}
status code: 200
- Multiple records or persons can have the same name, an ID will make them unique
- Crud operations will be made using a unique identifier id which is provided upon create operation