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

Contact List API

Difficulty

  • intermediate

Average duration

16 hrs

Technologies

  • REST

  • Django

    Python

    Flask

  • APIs

Difficulty

  • intermediate

Average duration

16 hrs

Technologies

📝 Instructions

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
1REQUEST (application/json) 2 type: GET 3 body: null 4RESPONSE (application/json) 5 code: 200 | 404 | 500 6 body: [ 7 { 8 "full_name": "Dave Bradley", 9 "email": "dave@gmail.com", 10 "address":"47568 NW 34ST, 33434 FL, USA", 11 "phone":"7864445566", 12 "groups": [2,3] 13 }, 14 ... 15 ]
  1. Create a new contact
1REQUEST (application/json) 2 type: POST 3 path: /contact 4 body: { 5 "full_name": "Dave Bradley", 6 "email": "dave@gmail.com", 7 "address":"47568 NW 34ST, 33434 FL, USA", 8 "phone":"7864445566", 9 "groups": [2,3] 10 } 11RESPONSE (application/json) 12 code: 200 | 400 | 500 13 body: { 14 "id": 12 15 "full_name": "Dave Bradley", 16 "email": "dave@gmail.com", 17 "address":"47568 NW 34ST, 33434 FL, USA", 18 "phone":"7864445566", 19 "groups": [2,3] 20 }
  1. Get a specific Contact
1REQUEST (application/json) 2 type: GET 3 path: /contact/{contact_id} 4RESPONSE (application/json) 5 code: 200 | 404 | 400 | 500 6 body:{ 7 "id": 12 8 "full_name": "Dave Bradley", 9 "email": "dave@gmail.com", 10 "address":"47568 NW 34ST, 33434 FL, USA", 11 "phone":"7864445566", 12 "groups": [ 13 { 14 "id": 2, 15 "name": "Family" 16 },{ 17 "id": 3, 18 "name": "Gamers" 19 } 20 ] 21 }
  1. Update a given contact
1REQUEST (application/json) 2 type: PUT 3 path: /contact/{contact_id} 4 body: { 5 "full_name": "Dave Bradley", 6 "email": "dave@gmail.com", 7 "address":"47568 NW 34ST, 33434 FL, USA", 8 "phone":"7864445566", 9 "groups": [2,3] 10 } 11RESPONSE (application/json) 12 code: 200 | 404 | 400 | 500 13 body:{ 14 "id": 12 15 "full_name": "Dave Bradley", 16 "email": "dave@gmail.com", 17 "address":"47568 NW 34ST, 33434 FL, USA", 18 "phone":"7864445566", 19 "groups": [2,3] 20 }
  1. Delete a contact by id
1REQUEST (application/json) 2 type: DELETE 3 path: /contact/{contact_id} 4 body: null 5RESPONSE (application/json) 6 code: 200 | 404 | 500 7 body: { 8 "deleted": { 9 "id": 12, 10 "full_name": "Dave Bradley", 11 } 12 }
  1. List all Groups
1REQUEST (application/json) 2 type: GET 3 path: /group/ 4 body: null 5RESPONSE (application/json) 6 code: 200 | 500 7 body: { 8 "data": [ 9 { 10 "id": 1, 11 "name": "Work" 12 },{ 13 "id": 2, 14 "name": "Gamers" 15 } 16 ] 17 }
  1. Get a specific Group
1REQUEST (application/json) 2 type: GET 3 path: /group/{group_id} 4RESPONSE (application/json) 5 code: 200 | 404 | 400 | 500 6 body:{ 7 "id": 2 8 "name": "Work", 9 "contacts": [ 10 { 11 "id": 12 12 "full_name": "Dave Bradley", 13 "email": "dave@gmail.com", 14 "address":"47568 NW 34ST, 33434 FL, USA", 15 "phone":"7864445566", 16 "groups": [2,3] 17 } 18 ] 19 }
  1. Update a given group's id
1 REQUEST (application/json) 2 type: PUT 3 path: /group/{group_id} 4 body: { 5 "name": "Beach Crew", 6 } 7 RESPONSE (application/json) 8 code: 200 | 404 | 400 | 500 9 body:{ 10 "id": 2 11 "name": "Beach Crew", 12 }
  1. Delete a group by id
1 REQUEST (application/json) 2 type: DELETE 3 path: /group/{group_id} 4 body: null 5 RESPONSE (application/json) 6 code: 200 | 404 | 500 7 body: { 8 "deleted": { 9 "id": 2, 10 "name": "Beach Crew", 11 } 12 }

💡 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

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

  • intermediate

Average duration

16 hrs

Technologies

Difficulty

  • intermediate

Average duration

16 hrs

Technologies

Difficulty

  • intermediate

Average duration

16 hrs

Technologies

Difficulty

  • intermediate

Average duration

16 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

  • intermediate

Average duration

16 hrs

Technologies

Difficulty

  • intermediate

Average duration

16 hrs

Technologies