Giter VIP home page Giter VIP logo

zuri_internship_task_2's Introduction

zuri_internship_task_2

Task 2 Repo

Build Status Tests Passed Code Style: Black

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

Person Model 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:

{
    "name": "Mark Essien"
}

Response:

{
    "id": 1,
    "name": "Mark Essien"
}

2. Retrieve a Person

Endpoint: GET /api/{user_id}/

Response:

{
    "id": 1,
    "name": "Mark Essien"
}

3. Update a Person

Endpoint: PUT /api/{user_id}/

Request:

{
    "name": "Mark Essien Updated"
}

Response:

{
    "id": 1,
    "name": "Mark Essien Updated"
}

4. Delete a Person

Endpoint: DELETE /api/{user_id}/

Response:

{
    "message": "Person with id 1 has been deleted"
}

Example Usage

# Creating a new person
import requests

url = "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 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:

zuri_internship_task_2's People

Contributors

brianobot avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.