Nodejs Express server with CRUD functionality.
Home Manager API is a Nodejs API that allows CRUD operations, to a PostgreSQL database, to store and manage home expenses and service providers.
Backend data repository: PostgreSQL database.
Packages used: express, morgan, cors, dotenv, helmet, winston, xss, pg, postgreSQL, knex, bcrypt.
All API requests must be made using an API Key. For testing purposes the following API key can be used:
Test API key: 6u4z8451-7ch3-1547-8e15-bf1419bf2315
If you clone this Git repository you'll want to store the API key in the .env file (more information on that below).
The API has the following endpoints:
-
users
: CRUD users for the app -
expenses
: CRUD expenses for a user -
service-providers
: CRUD service providers for a user -
addresses
: CRUD adresses for a service provider -
types
: CRUD expense and service providers types
-
Description: returns a user object for a provided username and password
-
Request params:
param name | type | param type |
---|---|---|
username | String | body |
password | String | body |
- Response:
A user object.
param name | type |
---|---|
id | Number |
username | String |
password | String |
-
Description: creates a user object
-
Request params:
param name | type | param type |
---|---|---|
username | String | body |
password | String | body |
- Response:
The user object created.
param name | type |
---|---|
id | Number |
username | String |
password | String |
-
Description: updates a user's password
-
Request params:
param name | type | param type |
---|---|---|
username | String | body |
password | String | body |
newPassword | String | body |
- Response:
The user object updated.
param name | type |
---|---|
id | numeric |
username | String |
password | String |
-
Description: deletes a user
-
Request params:
param name | type | param type |
---|---|---|
username | String | body |
password | String | body |
- Response: a string confirming the user is deleted.
-
Description: returns an array of expense objects for a provided user id
-
Request params:
param name | type | param type |
---|---|---|
user_id | Number | querystring |
- Response:
An array of expense objects.
param name | type |
---|---|
id | Number |
type_id | Number |
amount | Number |
name | String |
description | String |
date | Date |
user_id | Number |
-
Description: returns an expense object for a provided expense id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
- Response:
An expense object.
param name | type |
---|---|
id | Number |
type_id | Number |
amount | Number |
name | String |
description | String |
date | Date |
user_id | Number |
-
Description: creates an expense
-
Request params:
param name | type | param type |
---|---|---|
type_id | Number | body |
amount | Number | body |
name | String | body |
description | String | body |
date | Date | body |
user_id | Number | body |
- Response:
The expense object created.
param name | type |
---|---|
id | Number |
type_id | Number |
amount | Number |
name | String |
description | String |
date | Date |
user_id | Number |
-
Description: updates an expense
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
type_id | Number | body |
amount | Number | body |
name | String | body |
description | String | body |
date | Date | body |
user_id | Number | body |
- Response:
The expense object updated.
param name | type |
---|---|
id | Number |
type_id | Number |
amount | Number |
name | String |
description | String |
date | Date |
user_id | Number |
-
Description: deletes an expense
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
user_id | Number | body |
- Response:
A string confirming that the expense was deleted.
-
Description: returns an array of serviceprovider objects (and its addresses) for a provided user id
-
Request params:
param name | type | param type |
---|---|---|
user_id | Number | querystring |
- Response:
An array of expense objects.
param name | type |
---|---|
id | Number |
user_id | Number |
type_id | Number |
name | String |
description | String |
telephone | String |
String | |
address.street | String |
address.city | String |
address.state | String |
address.zipcode | String |
-
Description: returns a serviceprovider object (and its address) for a provided serviceprovider id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
- Response:
An expense object.
param name | type |
---|---|
id | Number |
user_id | Number |
type_id | Number |
name | String |
description | String |
telephone | String |
String | |
address.street | String |
address.city | String |
address.state | String |
address.zipcode | String |
-
Description: creates a serviceprovider (and its address)
-
Request params:
param name | type | param type |
---|---|---|
user_id | Number | body |
type_id | Number | body |
name | String | body |
description | String | body |
telephone | String | body |
String | body | |
address.street | String | body |
address.city | String | body |
address.state | String | body |
address.zipcode | String | body |
- Response:
The expense object created.
param name | type |
---|---|
id | Number |
user_id | Number |
type_id | Number |
name | String |
description | String |
telephone | String |
String | |
address.street | String |
address.city | String |
address.state | String |
address.zipcode | String |
-
Description: updates a serviceprovider (and its address)
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
user_id | Number | body |
type_id | Number | body |
name | String | body |
description | String | body |
telephone | String | body |
String | body | |
address.street | String | body |
address.city | String | body |
address.state | String | body |
address.zipcode | String | body |
-
Response:
-
The expense object updated.
param name | type |
---|---|
id | Number |
user_id | Number |
type_id | Number |
name | String |
description | String |
telephone | String |
String | |
address.street | String |
address.city | String |
address.state | String |
address.zipcode | String |
-
Description: deletes a serviceprovider (and its address)
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
user_id | Number | body |
- Response:
A string confirming that the service provided was deleted.
-
Description: creates an address
-
Request params:
param name | type | param type |
---|---|---|
street | String | body |
city | String | body |
state | String | body |
zipcode | String | body |
- Response:
The address object created.
param name | type |
---|---|
id | Number |
street | String |
city | String |
state | String |
zipcode | String |
-
Description: returns an address object for a provided address id
-
Request params:
param name | type | param type |
---|---|---|
id | Number | Querystring |
- Response:
An address object.
param name | type |
---|---|
id | Number |
street | String |
city | String |
state | String |
zipcode | String |
-
Description: updates an address
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
street | String | body |
city | String | body |
state | String | body |
zipcode | String | body |
- Response:
The address object updated.
param name | type |
---|---|
id | Number |
street | String |
city | String |
state | String |
zipcode | String |
-
Description: deletes an address
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
- Response:
A string confirming that the address has been deleted.
-
Description: returns an array of types
-
Request params:
None
- Response:
An array of type objects.
param name | type |
---|---|
id | Number |
name | String |
description | String |
-
Description: return a type object for a provided type id
-
Request params:
param name | type | param type |
---|---|---|
id | Numeric | Querystring |
- Response:
A type object.
param name | type |
---|---|
id | Number |
name | String |
description | String |
-
Description: creates a type
-
Request params:
param name | type | param type |
---|---|---|
name | String | body |
description | String | body |
- Response:
The type object created.
param name | type |
---|---|
id | Number |
name | String |
description | String |
-
Description: updates a type
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
name | String | body |
description | String | body |
- Response:
The type object updated.
param name | type |
---|---|
id | Number |
name | String |
description | String |
-
Description: deletes a type
-
Request params:
param name | type | param type |
---|---|---|
id | Number | querystring |
- Response:
A string confirming that the type object has been deleted.
Complete the following steps to start a new project (NEW-PROJECT-NAME):
- Clone this repository to your local machine
git clone https://github.com/rodrigohervas/home-manager-api.git NEW-PROJECT-NAME
cd
into the cloned repository- Make a fresh start of the git history for this project with
rm -r -Force .git
, amd thengit init
- Make sure that the .gitignore file is encoded as 'UTF-8'
- Install the node dependencies
npm install
- Add an
.env
file with the following content:- NODE_ENV='development'
- PORT=4000
- API_KEY=[YOUT_API_KEY_HERE]
- DATABASE_URL=[YOUR_CONNECTION_STRING_HERE]
- TEST_DATABASE_URL=[YOUR_CONNECTION_STRING_HERE]
- SALT_ROUNDS=10
- Edit the contents of the
package.json
to use NEW-PROJECT-NAME instead of"name": "home-manager-api"
Note. This server can be used with the following client repo: https://github.com/rodrigohervas/home-manager-client
(git clone https://github.com/rodrigohervas/home-manager-client NEW-PROJECT-NAME
)
Start the application npm start
Start nodemon for the application npm run dev