JavaScript PurAí API for Node.js Module in Node.js, Express and MySQL that provides an RESTful API. Made with MVC pattern. Support for authorization and authentication with JWT tokens.
This project package the following functions:
Features must be added:
Get via git clone:
$ git clone https://github.com/purai/nodejs_api.git
$ cd nodejs_api
Create a MySQL database without any tables. Then just set the database config at db-connect.js file:
const connection = mysql . createConnection ( { host : 'localhost' , port : 3306 , user : 'root' , password : 'root' , database : 'purai_app' } ) ; All tables will be add when server get started. You can, optionally, uncomment this call method at db-connect.js to add sample data in the tables: addSampleData(connection)
Get dependencies with Yarn :
Start the server with yarn start.
The application will automatically restart when files get changed due nodemon .
And the application will start at http://localhost:3000.
Used Swagger framework to document and test.
http://localhost:3000/documentation/
Send a POST request to http://localhost:3000/login with user parameters.
{
"email" : " string" ,
"password" : " string"
} To request locked methods set the header key Authorization and the token as value.
Curl request example with token curl -X POST "http://localhost:3000/events" -H "accept: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InN0cmluZ0BzdHJpbmcuY29tIiwidXNlcklkIjoiZDViNzJjMDAiLCJpYXQiOjE1MzUyMjcwNTh9.OcIZ0EMDale9Ry5PvDYQAKtup1znaQc2Iti1iBPaBlE"
POST http://localhost:3000/login Parameter Type Required Description bodyobject ✅ Pass login data object in body
Login object example with sample data {
"email" : " admin@mail.com" ,
"password" : " admin"
} GET http://localhost:3000/user Parameter Type Required Description statusint ❌ GET filtered by status. (1: Active, 0: Inactive) uuidstring ❌ GET filtered by UUID. (e.g.: dbfdd3d0-a808-11e8-aa56-a3de1ec713c5)
DELETE http://localhost:3000/user/{uuid} Parameter Type Required Description uuidstring ✅ User UUID to get deleted
POST http://localhost:3000/user/signup Parameter Type Required Description bodyobject ✅ Pass user data object in body
PUT http://localhost:3000/user/{uuid} Parameter Type Required Description uuidstring ✅ User UUID to get changed bodyobject ✅ Pass user data object in body
{
"status" : 1 ,
"name" : " string" ,
"email" : " string@mail.com" ,
"password" : " string"
} User data response example {
"users" : [
{
"uuid" : " dbfdd3d0-a808-11e8-aa56-a3de1ec713c5" ,
"status" : 1 ,
"name" : " admin" ,
"email" : " admin@mail.com"
}
]
} GET http://localhost:3000/events Parameter Type Required Description statusint ❌ GET filtered by status. (1: Active, 0: Inactive) featuredint ❌ GET filtered by featured. (1: True, 0: False) uuidstring ❌ GET filtered by UUID. (e.g.: 955b9575-e542-461c-939a-5ef41e733859) searchstring ❌ GET filtered by term in event title, place, address and city pageint ❌ GET filtered by page number considering limit value. (Default page is 1) limitint ❌ GET filtered by limit informed. If 0 returns all records. (Default value is 10) upcomingstring ❌ deprecated GET filtered by upcoming events. By default only events with a date greater than or equal to the current date will be returned. Date format yyyy-MM-ddcategorystring ❌ GET filtered by terms in category name saleplacestring ❌ GET filtered by terms in sale places name
DELETE http://localhost:3000/events/{uuid} Parameter Type Required Description uuidstring ✅ Event's UUID to get deleted
POST http://localhost:3000/events Parameter Type Required Description bodyobject ✅ Pass event data object in body
PUT http://localhost:3000/events/{uuid} Parameter Type Required Description uuidstring ✅ Event's UUID to get changed bodyobject ✅ Pass event data object in body
Event data object example {
"status" : 1 ,
"featured" : 0 ,
"title" : " string" ,
"image" : File, "about" : " string" ,
"price" : " string" ,
"date" : " 2022-01-01 20:00" ,
"address" : " string" ,
"city" : " string" ,
"id_category" : 1 ,
"id_sale_place" : 1
} Event data response example {
"events" : [
{
"id" : 1 ,
"uuid" : " 955b9575-e542-461c-939a-5ef41e733859" ,
"status" : 1 ,
"featured" : 0 ,
"created_at" : " 2022-01-01T00:00:00" ,
"updated_at" : " 2022-01-01T00:00:00" ,
"title" : " Sample Event" ,
"image" : " http://localhost:3000/uploads/events/sample-event.jpg" ,
"about" : " Sample event description" ,
"price" : " R$ 100,00" ,
"date" : " 2022-01-01T00:00:00" ,
"address" : " Apple Campus, Cupertino, CA 95014, EUA" ,
"city" : " Cupertino" ,
"id_category" : 1 ,
"id_sale_place" : 1 ,
"sale_place" : {
"id" : 1 ,
"uuid" : " ffd9d343-585a-40ee-bc58-c1e6935dcbdd" ,
"status" : 1 ,
"title" : " Entre em contato para mais detalhes" ,
"phone" : " "
},
"category" : {
"id" : 1 ,
"uuid" : " 1670d1f8-8d9e-46bb-8a19-b85cdd27e016" ,
"status" : 1 ,
"title" : " Festa e Show" ,
"category_image" : " http://localhost:3000/uploads/categories/sample-category.jpg"
}
}
]
} GET http://localhost:3000/categories Parameter Type Required Description statusint ❌ GET filtered by status. (1: Active, 0: Inactive) uuidstring ❌ GET filtered by UUID. (e.g.: 1670d1f8-8d9e-46bb-8a19-b85cdd27e016) searchstring ❌ GET filtered by term in category title pageint ❌ GET filtered by page number considering limit value. (Default page is 1) limitint ❌ GET filtered by limit informed. If 0 returns all records. (Default value is 10)
DELETE http://localhost:3000/categories/{uuid} Parameter Type Required Description uuidstring ✅ Category's UUID to get deleted
POST http://localhost:3000/categories Parameter Type Required Description bodyobject ✅ Pass category data object in body
PUT http://localhost:3000/categories/{uuid} Parameter Type Required Description uuidstring ✅ Category's UUID to get changed bodyobject ✅ Pass category data object in body
Category data object example {
"status" : 1 ,
"title" : " string" ,
"category_image" : File
} Category data response example {
"categories" : [
{
"id" : 1 ,
"uuid" : " 1670d1f8-8d9e-46bb-8a19-b85cdd27e016" ,
"status" : 1 ,
"title" : " Festa e Show" ,
"category_image" : " http://localhost:3000/uploads/categories/sample-category.jpg"
},
{
"id" : 2 ,
"uuid" : " 2ddbd4bd-527a-428b-b640-d3f9318b06b8" ,
"status" : 1 ,
"title" : " Curso e Workshop" ,
"category_image" : " http://localhost:3000/uploads/categories/sample-category.jpg"
}
]
} GET http://localhost:3000/salePlaces Parameter Type Required Description statusint ❌ GET filtered by status. (1: Active, 0: Inactive) uuidstring ❌ GET filtered by UUID. (e.g.: ffd9d343-585a-40ee-bc58-c1e6935dcbdd) searchstring ❌ GET filtered by term in sale place title pageint ❌ GET filtered by page number considering limit value. (Default page is 1) limitint ❌ GET filtered by limit informed. If 0 returns all records. (Default value is 10)
DELETE http://localhost:3000/salePlaces/{uuid} Parameter Type Required Description uuidstring ✅ Sale Places' UUID to get deleted
POST http://localhost:3000/salePlaces Parameter Type Required Description bodyobject ✅ Pass sale place data object in body
PUT http://localhost:3000/salePlaces/{uuid} Parameter Type Required Description uuidstring ✅ Sale Places' UUID to get changed bodyobject ✅ Pass sale place data object in body
Sale Place data object example {
"status" : 1 ,
"title" : " string" ,
"phone" : " string"
} Sale Place data response example {
"sale_places" : [
{
"id" : 1 ,
"uuid" : " ffd9d343-585a-40ee-bc58-c1e6935dcbdd" ,
"status" : 1 ,
"title" : " Entre em contato para mais detalhes" ,
"phone" : " "
}
]
} This project is licensed under the GNU GPLv3 License - see the LICENSE file for details
Made with ❤️ by Felipe Mendes .