Signup and get access to similar projects
Every week, we pick a real-life project to build your portfolio and get ready for a job. All projects are built with ChatGPT as co-pilot!
Start the ChallengeA tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.
Listen the podcastThe Jackson Family needs a static API! We need to build the data structures and create API endpoint to interact with it using Postman.
This project comes with the necessary files to start working immediately.
We recommend opening this very same repository using a provisioning tool like Codespaces (recommended) or Gitpod. Alternatively, you can clone it on your local computer using the git clone
command.
This is the repository you need to open:
1https://github.com/breatheco-de/exercise-family-static-api
π Please follow these steps on how to start a coding project.
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
Create the code needed to implement the API endpoints described further below.
The only two files you have to edit are:
src/datastructure.py
: Contains the class with the rules on how to manage the family members.src/app.py
: Contains the API, it uses the Family as data structure.$ pipenv run test
on the command line.Every member of the Jackson family must be a dictionary - the equivalent of Objects Literals in JS - and have these values:
1 + id: Int 2 + first_name: String 3 + last_name: String (Always Jackson) 4 + age: Int > 0 5 + lucky_numbers: Array of int
The family data-structure will be a class with the following structure:
1class Family: 2 3 def __init__(self, last_name): 4 self.last_name = last_name 5 # example list of members 6 self._members = [{ 7 "id": self._generateId(), 8 "first_name": "John", 9 "last_name": last_name 10 }] 11 12 # read-only: Use this method to generate random members ID's when adding members into the list 13 def _generateId(self): 14 return random.randint(0, 99999999) //import random 15 16 def add_member(self, member): 17 ## you have to implement this method 18 ## append the member to the list of _members 19 pass 20 21 def delete_member(self, id): 22 ## you have to implement this method 23 ## loop the list and delete the member with the given id 24 pass 25 26 def update_member(self, id, member): 27 ## you have to implement this method 28 ## loop the list and replace the member with the given id 29 pass 30 31 def get_member(self, id): 32 ## you have to implement this method 33 ## loop all the members and return the one with the given id 34 pass 35 36 def get_all_members(self): 37 return self._members
Note: don't forget to initialize the class: jackson_family = FamilyStructure('Jackson')
before the routes.
1John Jackson 233 Years old 3Lucky Numbers: 7, 13, 22 4 5Jane Jackson 635 Years old 7Lucky Numbers: 10, 14, 3 8 9Jimmy Jackson 105 Years old 11Lucky Numbers: 1
This API must have 4 endpoints. They all return JSON:
Which returns all members of the family.
1GET /members 2 3status_code: 200 if success. 400 if bad request (wrong info) screw up, 500 if the server encounter an error 4 5RESPONSE BODY (content-type: application/json): 6 7[], // List of members. 8
Which returns the member of the family where id == member_id
.
1GET /member/<int:member_id> 2 3RESPONSE (content_type: application/json): 4 5status_code: 200 if success. 400 if bad request (wrong info) screw up, 500 if the server encounter an error 6 7body: //the member's json object 8 9{ 10 "id": Int, 11 "first_name": String, 12 "age": Int, 13 "lucky_numbers": List 14} 15
Which adds a new member to the family data structure.
1POST /member 2 3REQUEST BODY (content_type: application/json): 4 5{ 6 first_name: String, 7 age: Int, 8 lucky_numbers: [], 9 id: Int *optional 10} 11 12RESPONSE (content_type: application/json): 13 14status_code: 200 if success. 400 if a bad request (wrong info) screw up, 500 if the server encounters an error 15 16body: empty
Keep in mind that POST request data dictionary may contain a key and a value for this new member id
.
Which deletes a family member with id == member_id
1DELETE /member/<int:member_id> 2 3RESPONSE (content_type: application/json): 4 5status_code: 200 if success. 400 if a bad request (wrong info) screw up, 500 if the server encounters an error 6 7body: { 8 done: True 9} 10
200
for success, 400
for bad request or 404
for not found.This and many other projects are built by students as part of the 4Geeks Academy Coding Bootcamp by Alejandro Sanchez and many other contributors. Find out more about our Full Stack Developer Course, and Data Science Bootcamp.
Signup and get access to similar projects
Every week, we pick a real-life project to build your portfolio and get ready for a job. All projects are built with ChatGPT as co-pilot!
Start the ChallengeA tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.
Listen the podcast