4Geeks logo
4Geeks logo

Courses

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Coding Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Full-Stack Software Developer - 16w

Data Science and Machine Learning - 16 wks

Search from all Lessons


LoginGet Started
← Back to Projects

Family Static API with Flask

Difficulty

  • easy

Average duration

8 hrs

Technologies

  • Data Structures

  • Serialization

  • Python

  • json

  • Flask

  • REST

  • APIs

Difficulty

  • easy

Average duration

8 hrs

Technologies

Signup and get access to similar projects

We will use it to give you access to your account.
Already have an account? Login here.

Difficulty

  • easy

Average duration

8 hrs

Technologies

Difficulty

  • easy

Average duration

8 hrs

Technologies

Weekly Coding Challenge

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 Challenge

Podcast: Code Sets You Free

A tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.

Listen the podcast

The Jackson Family needs a static API! We need to build the data structures and create API endpoint to interact with it using Postman.

🌱 How to start this project

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.

πŸ’» Installation

  1. Install the project dependencies by running $ pipenv install.

  2. Get inside the virtual environment by running $ pipenv shell

  3. Start the server by running $ pipenv run start

  4. Test your code by running $ pipenv run test

βœ… Automatic grading

Test your code by running $ pipenv run test

πŸ“ Instructions

  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 family members.
  • src/app.py: Contains the API, it uses the Family as data structure.
  1. We have prepared a set of automated tests that will give you an idea if your code is correct, run the tests by typing $ pipenv run test on the command line.

Data structures

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.

These are the initial Family Members

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

Endpoints

This API must have 4 endpoints. They all return JSON:

1) Get all family members:

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

2) Retrieve one member

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

3) Add (POST) new member

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.

  • If it does not, your API should randomly generate one when adding family members.
  • If it does include it, that is the value to be used for such end.

4) DELETE one member

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

Requirements

  • All requests and responses should be in content/type: application/json
  • Response codes must be 200 for success, 400 for bad request or 404 for not found.
  • These exercises do not include a database, everything must be done in Runtime (RAM).

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.

Difficulty

  • easy

Average duration

8 hrs

Technologies

Difficulty

  • easy

Average duration

8 hrs

Technologies

Signup and get access to similar projects

We will use it to give you access to your account.
Already have an account? Login here.

Difficulty

  • easy

Average duration

8 hrs

Technologies

Difficulty

  • easy

Average duration

8 hrs

Technologies

Weekly Coding Challenge

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 Challenge

Podcast: Code Sets You Free

A tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.

Listen the podcast