This repository keeps simple projects I do for recollect, practice and buff up programming learnings.
The objective of this project is practicing basic object-oriented programming with JavaScript. I also used it for practing node.js vanilla, developing a simple RESTful API with SQLite database, able to perform a simple CRUD.
Endpoints: route to access the functionalities
/api/person (Create route)
/api/person (Read route - all registers)
/api/person/:id (Read route - a register by id)
/api/person/resouce?name=[name] (Read route - registers by name)
/api/person (Update route - a specif register)
/api/person/:uuid (Deltele route - a specif register)
All the routes and how to consume the API will be described bellow.
Request url:
/api/person
Example of request's body:
{
"firstName": "Yuri",
"lastName": "Rocha",
"birthdate": "2000-10-25",
"height": 1.85,
"weight": 80.1
}
Example of expecting response:
{
"id": "6b589c6a-61c2-4255-bdeb-4e62edcd0279",
"firstName": "Yuri",
"lastName": "Rosa",
"height": 1.85,
"weight": 80.1,
"birthdate": "2000-10-25"
}
Example of how to use it in JavaScript:
const data = {
"firstName": "Yuri",
"lastName": "Rocha",
"birthdate": "2000-10-25",
"height": 1.85,
"weight": 80.1
}
fetch('http://localhost:3333/api/person', {
method: "POST",
body: JSON.stringify(data)
})
.then(response => response.json())
.then(json => console.log(json));
Request url:
/api/person
Example of expecting response:
{
"data": [
{
"id": "5bd8c96a-2745-434b-891c-d9af8b872b77",
"firstName": "Wesley",
"lastName": "Souza",
"height": 1.92,
"weight": 85,
"birthdate": "2000-10-28T00:00:00.000Z"
},
{
"id": "6b589c6a-61c2-4255-bdeb-4e62edcd0279",
"firstName": "Yuri",
"lastName": "Rocha",
"height": 1.85,
"weight": 80.1,
"birthdate": "2000-10-25T00:00:00.000Z"
}
]
}
Example of how to use it in Javascript:
fetch('http://localhost:3333/api/person', {
method: "GET"
})
.then(response => response.json())
.then(json => console.log(json));
Request url:
/api/person/:id
Example of expecting response:
{
"data": [
{
"id": "ad1909d8-8c94-44ce-898d-89de76198268",
"firstName": "Yuri",
"lastName": "Rosa",
"height": 1.8,
"weight": 75.4,
"birthdate": "1998-10-25T00:00:00.000Z"
}
]
}
Example of how to use it in Javascript:
fetch('http://localhost:3333/api/person/ad1909d8-8c94-44ce-898d-89de76198268', {
method: "GET"
})
.then(response => response.json())
.then(json => console.log(json));
Request url:
/api/person/resource?name=[name]
Example of expecting response:
{
"data": [
{
"id": "6b589c6a-61c2-4255-bdeb-4e62edcd0279",
"firstName": "Yuri",
"lastName": "Rocha",
"height": 1.8,
"weight": 78.1,
"birthdate": "2000-10-24T00:00:00.000Z"
},
{
"id": "ad1909d8-8c94-44ce-898d-89de76198268",
"firstName": "Yuri",
"lastName": "Rosa",
"height": 1.8,
"weight": 75.4,
"birthdate": "1998-10-25T00:00:00.000Z"
}
]
}
Example of how to use it in Javascript:
fetch('http://localhost:3333/api/person/resource?name=Yuri%20Ro', {
method: "GET"
})
.then(response => response.json())
.then(json => console.log(json));
Request's url:
/api/person
Example of request's body:
{
"id" : "6b589c6a-61c2-4255-bdeb-4e62edcd0279",
"firstName": "Yuri",
"lastName": "Lemos",
"birthdate": "2001-05-24",
"height": 1.80,
"weight": 78.1
}
Expecting response:
{
{
"id": "6b589c6a-61c2-4255-bdeb-4e62edcd0279",
"firstName": "Yuri",
"lastName": "Lemos",
"height": 1.8,
"weight": 78.1,
"birthdate": "2001-05-24"
}
}
Example of how to use it on JavaScript:
const data = {
"id" : "6b589c6a-61c2-4255-bdeb-4e62edcd0279",
"firstName": "Yuri",
"lastName": "Lemos",
"birthdate": "2001-05-24",
"height": 1.80,
"weight": 78.1
}
fetch('http://localhost:3333/api/person', {
method: "PUT",
body: JSON.stringify(data)
})
.then(response => response.json())
.then(json => console.log(json));
Request url:
/api/person/:uuid
Example of expecting response:
{
"deleteMessage": "Pessoa deletada com sucesso!"
}
Example of how to use it in Javascript:
fetch('http://localhost:3333/api/person/6b589c6a-61c2-4255-bdeb-4e62edcd0279', {
method: "DELETE"
})
.then(response => response.json())
.then(json => console.log(json));