A basic node app to show the implementation of a Rest API with a basic CRUD for data about animals 🐶
- Have installed node.js
You can found this resources at:
- Clone the repository
git clone https://github.com/WilliBobadilla/nodejsApi
- Enter in the folder
cd nodejsApi
- Install dependencies
npm install
- Run the server
npm start
It will launch a local server in localhost:3000
This CRUD is about animals in a vet, all the information is stored in the DB with the following schema
- id: Integer (PK)
- name: String
- age: Integer
- type: Integer
- direction: String
- id: Integer(PK)
- name: String
- lastName: String
- phoneNumber: String
- idNumber: String
- email: String
- password: String
- direction: String
Data to send in point 2 of the User endpoint: http://localhost:3000/v1/user/login
//body data, to login and to test the api
{
"email":"willi1997.1@gmail.com",
"password":"admin321",
}
-
Create User
- HTTP Method: POST
- Authorization: NOT REQUIRED
- URL: http://localhost:3000/v1/user/
- Body Parameters:
- name: String
- lastName: String
- phoneNumber: String
- idNumber: String
- email: String
- password: String
- direction: String
//example data for body: { "name":"Williams", "lastName":"Bobadilla", "phoneNumber":"0979874", "idNumber":"999999", "email":"willi1997.1@gmail.com", "password":"admin321", "direction":"San antonio" }
-
Login with your User
-
HTTP Method: POST
-
Authorization: NOT REQUIRED
-
Body Parameters:
-
email: String
-
password: String
//example data for body: { "email":"willi1997.1@gmail.com", "password":"admin321" }
-
-
Response example:
{ "user": { "id": 1, "name": "Williams", "lastName": "Bobadilla", "phoneNumber": "0979874", "idNumber": "999999", "email": "willi1997.1@gmail.com", "password": "admin321", "direction": "San antonio", "createdAt": "2021-05-04T16:59:44.866Z", "updatedAt": "2021-05-04T16:59:44.866Z" }, "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJ3aWxsaTE5OTcuMUBnbWFpbC5jb20iLCJpYXQiOjE2MjAxNDc1ODcsImV4cCI6MTYyMDE0NzU4N30.xhG5tZAgeZ5Q1IpLFVdFKJj1FTh9pXGzeLMdR_snYtI" }
-
Note: In this point, all the requests to the Animal endpoints and User endpoints have to have the Authorization parameter in header of the request, this authorization parameter is the token in the response of the login!
-
Get all users
- HTTP Method: GET
- Authorization: REQUIRED
- URL: http://localhost:3000/v1/user
- Body response example:
[ { "id": 1, "name": "Williams", "lastName": "Bobadilla", "phoneNumber": "777777", "idNumber": "123654789", "email": "willi1997.1@gmail.com", "password": "", "direction": "San Roque", "createdAt": "2021-05-05T03:15:31.871Z", "updatedAt": "2021-05-05T03:15:31.871Z" } ]
-
Get User by id
-
HTTP Method: GET
-
Authorization: REQUIRED
-
Body response example:
{ "id": 1, "name": "Williams", "lastName": "Bobadilla", "phoneNumber": "777777", "idNumber": "123654789", "email": "willi1997.1@gmail.com", "password": "", "direction": "San Roque", "createdAt": "2021-05-05T03:15:31.871Z", "updatedAt": "2021-05-05T03:15:31.871Z" }
-
-
Update User
-
HTTP Method: PUT
-
Authorization: REQUIRED
-
Body Parameters(just parameters to be added have to be in body):
-
name: String
-
lastName: String
-
phoneNumber: String
-
idNumber: String
-
email: String
-
password: String
-
direction: String
//example data for body: { "name":"Williams", "lastName":"Bobadilla", "phoneNumber":"777777", "idNumber":"123654789", "email":"willi1997.1@gmail.com", "password":"admin321", "direction":"San Roque" }
-
-
-
Delete User
- HTTP Method: DELETE
- Authorization: REQUIRED
- URL: http://localhost:3000/v1/user/{id}
- Body response example:
{ "msg": "Deleted successully", "id": "1" }
Important Note: Is not implemented yet the verification of who is deleting the user account, so for now, whatever user can delete whatever account! In this case we have to filter just if the user is deleting his own account!
-
Create Animal
-
HTTP Method: POST
-
Authorization: REQUIRED
-
Body Parameters:
-
name: String
-
age: Integer
-
type: Integer
-
direction: String
//example data for body: { "name":"Pinkie", "age":10, "type":0, "direction":"Fossati y Palma, San Antonio" }
-
-
-
List animals
-
HTTP Method: GET
-
Authorization: REQUIRED
-
Body response example:
//example of request response: [ { "id":1 "name":"Pinkie", "age":10, "type":0, "direction":"Fossati y Palma, San Antonio", "createdAt": "2021-04-30T23:03:07.837Z", "updatedAt": "2021-04-30T23:03:07.837Z" }, { "id":2 "name":"Dobbie", "age":3, "type":1, "direction":"Bartolome mitre, San Lorenzo", "createdAt": "2021-04-30T23:04:08.837Z", "updatedAt": "2021-04-30T23:04:08.837Z" } ]
-
-
Get an animal
-
HTTP Method: GET
-
Authorization: REQUIRED
-
Body response example:
{ "id": 1, "name": "Blanquie", "age": 12, "type": 1, "direction": "San Francisco", "createdAt": "2021-04-30T23:03:07.837Z", "updatedAt": "2021-04-30T23:03:07.837Z" }
-
-
Update an animal
-
HTTP Method: PUT
-
Authorization: REQUIRED
-
Body Parameters:
-
name: String
-
age: Integer
-
type: Integer
-
direction: String
//example data for body: { "name":"Pinkie", "age":11, "type":0, "direction":"Fossati y Palma, San Antonio" }
-
-
-
Delete an animal
- HTTP Method: DELETE
- Authorization: REQUIRED
- URL: http://localhost:3000/v1/animals/{id}
- Body response example:
{ "msg": "Deleted successully", "id": "1" }
- Now all users can delete to another user, so we have to add a role and also the validations for that
- Add encription for password storage
Copyright 2021 Williams Bobadilla
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.