4Geeks Coding Projects tutorials and exercises for people learning to code or improving their coding skills
Difficulty
beginnerRepository
Click to openVideo
Not available
Live demo
Not available
Average duration
8 hrs
The Jackson Family needs a static API! We need to build the data structures and create API endpoint to interact with it using Postman.
Open the project with gitpod by clicking here, or clone it locally if you need.
Install the project dependencies by running $ pipenv install
.
Get inside the virtual environment by running $ pipenv shell
Start the server by running $ pipenv run start
Test your code by running $ pipenv run test
Test your code by running $ pipenv run test
1) Create the code needed to implement the API endpoints described further below.
2) The only two files you have to edit are:
src/datastructure.py
: Contains the class with the rules on how to manage the fammily members.src/app.py
: Contains the API, it uses the Family as datastructure.
$ pipenv run tests
on the command line.Every member of the Jackson family must be a dictionary - equivalent of Objects Literals in JS - and have these values:
+ id: Int + first_name: String + last_name: String (Always Jackson) + age: Int > 0 + lucky_numbers: Array of int
The family data-structure will be a class with the following structure:
class Family: def __init__(self, last_name): self.last_name = last_name # example list of members self._members = [{ "id": self._generateId(), "first_name": "John", "last_name": last_name }] # read-only: Use this method to generate random members ID's when adding members into the list def _generateId(self): return random.randint(0, 99999999) //import random def add_member(self, member): ## you have to implement this method ## append the member to the list of _members pass def delete_member(self, id): ## you have to implement this method ## loop the list and delete the member with the given id pass def update_member(self, id, member): ## you have to implement this method ## loop the list and replace the member with the given id pass def get_member(self, id): ## you have to implement this method ## loop all the members and return the one with the given id pass def get_all_members(self): return self._members
Note: don't forget to Initialize the class: jackson_family = FamilyStructure('Jackson')
before the routes.
John Jackson 33 Years old Lucky Numbers: 7, 13, 22 Jane Jackson 35 Years old Lucky Numbers: 10, 14, 3 Jimmy Jackson 5 Years old Lucky Numbers: 1
This API must have 4 endpoints. They all return JSON:
Which returns all members of the family.
GET /members status_code: 200 if success. 400 if bad request (wrong info) screw up, 500 if the server encounter an error RESPONSE BODY (content-type: application/json): [], // List of members.
Which returns the member of the family where id == member_id
.
GET /member/<int:member_id> RESPONSE (content_type: application/json): status_code: 200 if success. 400 if bad request (wrong info) screw up, 500 if the server encounter an error body: //the member's json object { "id": Int, "first_name": String, "age": Int, "lucky_numbers": List }
Which adds a new member to the family data structure.
POST /member REQUEST BODY (content_type: application/json): { first_name: String, age: Int, lucky_numbers: [], id: Int *optional } RESPONSE (content_type: application/json): status_code: 200 if success. 400 if bad request (wrong info) screw up, 500 if the server encounter an error body: empty
Keep in mind that POST request data dictionary may contain a key and a value for this new member id
.
- If it does not, your API should randomly generate one when adding as a family members.
- If it does include it, then that is the value to be used for such end.
Which deletes a family member with id == member_id
DELETE /member/<int:member_id> RESPONSE (content_type: application/json): status_code: 200 if success. 400 if bad request (wrong info) screw up, 500 if the server encounter an error body: { done: True }
200
for success, 400
for bad request or 404
for not found.4Geeks Coding Projects tutorials and exercises for people learning to code or improving their coding skills
Difficulty
beginnerRepository
Click to openVideo
Not available
Live demo
Not available
Average duration
8 hrs
All rights reserved, 4Geeks LLC 2021. Read more about 4Geeks and what we are going here.