4Geeks Coding Projects tutorials and exercises for people learning to code or improving their coding skills
Difficulty
unknownRepository
Click to openVideo
Not available
Live demo
Not available
Average duration
16 hrs
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.
Create an API with the following endpoints:
GET /contact/all
POST /contact
GET /contact/{contact_id}
DELETE /contact/{contact_id}
UPDATE /contact/{contact_id}
GET /group/all
POST /group
GET /group/{group_id}
UPDATE /group/{group_id}
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)
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]
},
...
]
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]
}
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"
}
]
}
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]
}
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",
}
}
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"
}
]
}
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]
}
]
}
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",
}
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",
}
}
fetch
.Hint: Use Postman as a testing tool before you connect your front end application (React Contact List).
This exercise will make you practice the following fundamentals:
4Geeks Coding Projects tutorials and exercises for people learning to code or improving their coding skills
Difficulty
unknownRepository
Click to openVideo
Not available
Live demo
Not available
Average duration
16 hrs