The Jackson Family needs a static API! We need to build the data structures and create the API endpoints to interact with it using Hoppscotch (recommended) or 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
$ 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: List of integers
The family data-structure will be a class with the following structure:
1class FamilyStructure: 2 def __init__(self, last_name): 3 self.last_name = last_name 4 self._next_id = 1 5 self._members = [] 6 7 # This method generates a unique 'id' when adding members into the list (you shouldn't touch this function) 8 def _generate_id(self): 9 generated_id = self._next_id 10 self._next_id += 1 11 return generated_id 12 13 def add_member(self, member): 14 ## You have to implement this method 15 ## Append the member to the list of _members 16 pass 17 18 def delete_member(self, id): 19 ## You have to implement this method 20 ## Loop the list and delete the member with the given id 21 pass 22 23 def get_member(self, id): 24 ## You have to implement this method 25 ## Loop all the members and return the one with the given id 26 pass 27 28 def get_all_members(self): 29 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). 500 if the server encounters an error 4 5RESPONSE BODY (content-type: application/json): 6 7[] <!--- List of members -->
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). 500 if the server encounters an error 6 7 8body: <!--- The member's json object --> 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 id: Int, 6 first_name: String, 7 age: Int, 8 lucky_numbers: [] 9} 10 11RESPONSE (content_type: application/json): 12 13status_code: 200 if success. 400 if a bad request (wrong info). 500 if the server encounters an error
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). 500 if the server encounters an error 6 7body: { 8 done: True 9}
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.
In order to prepare better for completing this exercises, we suggest the following materials