4Geeks logo
4Geeks logo
About us

Learning library

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

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

Full-Stack Software Developer

Data Science and Machine Learning - 16 wks

Search from all Lessons

Social & live learning

The most efficient way to learn: Join a cohort with classmates just like you, live streams, impromptu coding sessions, live tutorials with real experts, and stay motivated.

← Back to Projects

Continue learning for free about:

Contact List API

Goal

4Geeks Coding Projects tutorials and exercises for people learning to code or improving their coding skills

Difficulty

intermediate

Repository

Click to open

Video

Not available

Live demo

Not available

Average duration

16 hrs

Technologies

alt text Contact List REST API in Flask

Creating and maintaining REST APIs is THE everyday job for most of back-end developers, so it is a skill that we need to mature. In this project we'll practice every step of the API development process.

We are going to build the API that manages a contact-list database and publicly expose the endpoints so client applications (including ours) can use it. This time we'll include Groups, a new entity that will allow the system to group Contacts. Example: Work, Family, Friends. Hint: we can implement this logic by using a many-to-many relationship between the two tables.

πŸ“ Instructions

Create an API with the following endpoints:

  1. Get a list of all the Contacts GET /contact/all
  2. Create a new Contact POST /contact
  3. Get a specific Contact (with the Group objects it belongs to) GET /contact/{contact_id}
  4. Delete a Contact DELETE /contact/{contact_id}
  5. Update a Contact UPDATE /contact/{contact_id}
  6. Get a list of all the Group names and ids GET /group/all
  7. Create a new Group POST /group
  8. Get a specific Group (with all Contact objects related to it) GET /group/{group_id}
  9. Update a Group name UPDATE /group/{group_id}
  10. Delete a Group DELETE /group/{group_id}

A contact must have the following data-structure on the database:

1# Contact 2 id: (int, primary_key) 3 full_name: (string, mandatory) 4 email: (string, mandatory) 5 address: (string, optional) 6 phone: (string, optional) 7 groups: (list of foreign_key) 8 9# Group 10 id: (int, primary_key) 11 name: (string, mandatory) 12 contacts: (list of foreign_key)

Formal API Documentation

  1. GET /contact/all
    REQUEST (application/json)
        type: GET
        body: null
    RESPONSE (application/json)
        code: 200 | 404 | 500
        body: [
            {
                "full_name": "Dave Bradley",
                "email": "dave@gmail.com",
                "address":"47568 NW 34ST, 33434 FL, USA",
                "phone":"7864445566",
                "groups": [2,3]
            },
            ...
        ]
  1. Create a new contact
    REQUEST (application/json)
        type: POST
        path: /contact
        body: {
            "full_name": "Dave Bradley",
            "email": "dave@gmail.com",
            "address":"47568 NW 34ST, 33434 FL, USA",
            "phone":"7864445566",
            "groups": [2,3]
        }
    RESPONSE (application/json)
        code: 200 | 400 | 500
        body: {
            "id": 12
            "full_name": "Dave Bradley",
            "email": "dave@gmail.com",
            "address":"47568 NW 34ST, 33434 FL, USA",
            "phone":"7864445566",
            "groups": [2,3]
        }
  1. Get a specific Contact
    REQUEST (application/json)
        type: GET
        path: /contact/{contact_id}
    RESPONSE (application/json)
        code: 200 | 404 | 400 | 500
        body:{
            "id": 12
            "full_name": "Dave Bradley",
            "email": "dave@gmail.com",
            "address":"47568 NW 34ST, 33434 FL, USA",
            "phone":"7864445566",
            "groups": [
                {
                    "id": 2,
                    "name": "Family"
                },{
                    "id": 3,
                    "name": "Gamers"
                }
             ]
        }
  1. Update a given contact
    REQUEST (application/json)
        type: PUT
        path: /contact/{contact_id}
        body: {
            "full_name": "Dave Bradley",
            "email": "dave@gmail.com",
            "address":"47568 NW 34ST, 33434 FL, USA",
            "phone":"7864445566",
            "groups": [2,3]
        }
    RESPONSE (application/json)
        code: 200 | 404 | 400 | 500
        body:{
            "id": 12
            "full_name": "Dave Bradley",
            "email": "dave@gmail.com",
            "address":"47568 NW 34ST, 33434 FL, USA",
            "phone":"7864445566",
            "groups": [2,3]
        }
  1. Delete a contact by id
    REQUEST (application/json)
        type: DELETE
        path: /contact/{contact_id}
        body: null
    RESPONSE (application/json)
        code: 200 | 404 | 500
        body: {
            "deleted": {
                "id": 12,
                "full_name": "Dave Bradley",
            }
        }
  1. List all Groups
    REQUEST (application/json)
        type: GET
        path: /group/
        body: null
    RESPONSE (application/json)
        code: 200 | 500
        body: {
            "data": [
                {
                    "id": 1,
                    "name": "Work"
                },{
                    "id": 2,
                    "name": "Gamers"
                }
            ]
        }
  1. Get a specific Group
    REQUEST (application/json)
        type: GET
        path: /group/{group_id}
    RESPONSE (application/json)
        code: 200 | 404 | 400 | 500
        body:{
            "id": 2
            "name": "Work",
            "contacts": [
                {
                    "id": 12
                    "full_name": "Dave Bradley",
                    "email": "dave@gmail.com",
                    "address":"47568 NW 34ST, 33434 FL, USA",
                    "phone":"7864445566",
                    "groups": [2,3]
                }
             ]
        }
  1. Update a given group's id
    REQUEST (application/json)
        type: PUT
        path: /group/{group_id}
        body: {
            "name": "Beach Crew",
        }
    RESPONSE (application/json)
        code: 200 | 404 | 400 | 500
        body:{
            "id": 2
            "name": "Beach Crew",
        }
  1. Delete a group by id
    REQUEST (application/json)
        type: DELETE
        path: /group/{group_id}
        body: null
    RESPONSE (application/json)
        code: 200 | 404 | 500
        body: {
            "deleted": {
                "id": 2,
                "name": "Beach Crew",
            }
        }

πŸ’‘ How to start?

  1. Start by reading the instructions very carefully.
  2. Build the database model class Contact and Group.
  3. Implement the add methods (POST) to be able to add some contacts and groups into the database to make sure you have dummy data.
  4. Create the GET(all) endpoints. List contacts and list groups.
  5. Implement the rest of the endpoints.
  6. Connect your React Contact List application using fetch.

Hint: Use Postman as a testing tool before you connect your front end application (React Contact List).

πŸ“– Fundamentals

This exercise will make you practice the following fundamentals:

  1. Reading API documentations
  2. Building an RESTful API
  3. Building data models
  4. SQL Databases
  5. REST API's
  6. Python Flask
  7. Fetch and async

Goal

4Geeks Coding Projects tutorials and exercises for people learning to code or improving their coding skills

Difficulty

intermediate

Repository

Click to open

Video

Not available

Live demo

Not available

Average duration

16 hrs