https://github.com/brianobot/zuri_internship_task_2
Task 2 Repo
https://github.com/brianobot/zuri_internship_task_2
api-service brian-obot internship internship-challenge internship-project internship-task zuri-internship-programme
Last synced: 3 months ago
JSON representation
Task 2 Repo
- Host: GitHub
- URL: https://github.com/brianobot/zuri_internship_task_2
- Owner: brianobot
- Created: 2023-09-10T15:14:01.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-12T14:20:38.000Z (almost 2 years ago)
- Last Synced: 2025-01-21T07:12:57.409Z (5 months ago)
- Topics: api-service, brian-obot, internship, internship-challenge, internship-project, internship-task, zuri-internship-programme
- Language: Python
- Homepage:
- Size: 87.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# zuri_internship_task_2
Task 2 Repo
[](https://github.com/brianobot/zuri_internship_task_2)
[](https://your-test-results-url)
[](https://github.com/psf/black)## 🌐 BASE URL: https://brianobot.pythonanywhere.com/
# Person Webservice Documentation
## Introduction
The **Person Webservice** is a RESTful API that allows users to interact with a `Person` resource. This webservice provides basic CRUD (Create, Read, Update, Delete) operations for managing `Person` objects.
### UML Diagram

### Resource: Person
A `Person` object represents an individual with a name.
#### Fields
- `name` (String, max length 100): The unique identifier of the person. It is a required field and must be a string.
## API Endpoints
### 1. Create a Person
**Endpoint:** `POST /api/`
**Request:**
```json
{
"name": "Mark Essien"
}
```**Response:**
```json
{
"id": 1,
"name": "Mark Essien"
}
```### 2. Retrieve a Person
**Endpoint:** `GET /api/{user_id}/`
**Response:**
```json
{
"id": 1,
"name": "Mark Essien"
}
```### 3. Update a Person
**Endpoint:** `PUT /api/{user_id}/`
**Request:**
```json
{
"name": "Mark Essien Updated"
}
```**Response:**
```json
{
"id": 1,
"name": "Mark Essien Updated"
}
```### 4. Delete a Person
**Endpoint:** `DELETE /api/{user_id}/`
**Response:**
```json
{
"message": "Person with id 1 has been deleted"
}
```## Example Usage
```python
# Creating a new person
import requestsurl = "https://brianobot.pythonanywhere.com/api"
payload = {
"name": "Mark Essien"
}
response = requests.post(url, json=payload)
print(response.json())# Retrieving a person
user_id = 1
url = f"https://brianobot.pythonanywhere.com/api/{user_id}/"
response = requests.get(url)
print(response.json())# Updating a person
user_id = 1
url = f"https://brianobot.pythonanywhere.com/api/{user_id}/"
payload = {
"name": "Mark Essien Updated"
}
response = requests.put(url, json=payload)
print(response.json())# Deleting a person
user_id = 1
url = f"https://brianobot.pythonanywhere.com/api/{user_id}/"
response = requests.delete(url)
print(response.json())
```## Error Handling
- **400 Bad Request:** If the request is malformed or missing required fields.
- **404 Not Found:** If the requested `Person` does not exist.
- **405 Method Not Allowed:** If an unsupported HTTP method is used on an endpoint.## Testing
To Run the Automated Test, run the command (from within the project directory terminal)
```python
python test.py
```## Conclusion
The Person Webservice provides a simple and easy-to-use interface for managing `Person` objects. It allows for creating, retrieving, updating, and deleting `Person` records through a RESTful API. Use the provided endpoints to interact with the service and manage your `Person` data.
### Maintainer:
- Brian Obot