Self-paced

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.

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.

Search from all Lessons


LoginGet Started

Register to 4Geeks

← 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

🌱 How to start this project
Endpoints

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.

🌱 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

✅ 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: 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.

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). 500 if the server encounters an error 4 5RESPONSE BODY (content-type: application/json): 6 7[] <!--- List of members -->

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). 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

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 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

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). 500 if the server encounters an error 6 7body: { 8 done: True 9}

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.

Sign up and get access to solution files and videos

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

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

8 hrs

Technologies

Difficulty

  • easy

Average duration

8 hrs

Technologies

Difficulty

  • easy

Average duration

8 hrs

Technologies

Difficulty

  • easy

Average duration

8 hrs

Technologies

Sign up and get access to solution files and videos

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

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

8 hrs

Technologies

Difficulty

  • easy

Average duration

8 hrs

Technologies

Supplementary Material

In order to prepare better for completing this exercises, we suggest the following materials

Lesson

Building RESTful API's using Flask

Exercise

Learn how to build HTTP requests with Python

Project

Interacting with an API using Python