This is a simple Node.js CRUD (Create, Read, Update, Delete) API that uses PostgreSQL as the database.
- Node.js
- PostgreSQL
-
Clone this repository to your local machine.
git clone https://github.com/jvcss/node-client-api.git
-
Install the dependencies using
pnpm install --filter client-api
ornpm
.npm install
-
Create a new PostgreSQL database and note the connection details (hostname, port, database name, username, and password).
- Watch this to know how to install PostgreSQL on Windows 64x: https://youtu.be/VMD_NnpXXSg
- Notice here we are using the version 15.2 of PostgreSQL
-
Create a .env file in the root of the project and fill it with the following values (replace with your own values):
PGHOST=<hostname>
PGPORT=<port>
PGDATABASE=<database name>
PGUSER=<username>
PGPASSWORD=<password>
- Start the server using
pnpm --filter client-api dev
ornpm dev
. The server should now be running on http://localhost:3000.- notice here we are using the nodemon to run the server in development mode
The following API endpoints are available:
List all clients with pagination.
Query parameters:
- page (optional): the page number (default: 1).
- limit (optional): the number of clients to return per page (default: 10).
Get a specific client by ID.
Path parameters:
- clientId: the ID of the client to get.
Create a new client.
Body parameters:
- fullName: the full name of the client (required).
- email: the email address of the client (required).
- telefone: the telephone number of the client (optional).
- coordinates: the coordinates of the client (optional).
Update an existing client by ID.
Path parameters:
- clientId: the ID of the client to update.
Body parameters:
- fullName: the full name of the client (required).
- email: the email address of the client (required).
- telefone: the telephone number of the client (optional).
- coordinates: the coordinates of the client (optional).
Delete a client by ID.
Path parameters:
- clientId: the ID of the client to delete.
Upload a list of clients using a specific txt file format
Body parameters:
- file: the file where each line is a new client.
Return the list of clients order by the specific position informed
Path parameters:
- lat: the latitude value of a user in db.
- lon: the longitude value of a user in db
- rad: the diameter
You can use Postman to test the API endpoints.
- Download and install Postman.
- Open Postman
- Import the ClientAPI.postman_col from postmanCollection folder.
- Click the Send button to make the tests, you can use your own data.
- The response will be displayed in the Response section.
You can use Jest to test the API endpoints.
- Install all dependecies
- run
pnpm --filter client-api test
ornpm test
- You can edit the package.json file to customize the test command:
"test": "jest flow.test.js --verbose"
- There is a file for each endpoint under the tests folder. To run a specific test, change the name of the file in the test command.
This is a ReactJS app that tests the API endpoints of a client management system. The app is composed of several panels, each one testing a specific endpoint. The panels are:
- Read File: Read a formatted file with client data.
- Create File: Create a formatted file with one client data.
- Upload File: Upload a file with client data to the server.
- Read Client: Read data from a single client.
- Edit Client: Edit data from a single client.
- Pageable List Clients: List clients with pagination.
- Delete Client: Delete a single client.
- Search Nearby: Search a list of clients given one specific position.
cd /path/to/docker-compose-file
docker-compose up --build
docker-compose up --build -d
docker-compose down
This project is licensed under the GNU License - see the LICENSE file for details.