https://github.com/ullaskunder3/meriadb-nodejs-restapi
This project is a simple REST API that allows you to manage user records. It is built using Node.js and MariaDB. You can create, retrieve, update, and delete user data using the provided endpoints.
https://github.com/ullaskunder3/meriadb-nodejs-restapi
crud-api db expressjs mariadb thunderclient vscode
Last synced: about 2 months ago
JSON representation
This project is a simple REST API that allows you to manage user records. It is built using Node.js and MariaDB. You can create, retrieve, update, and delete user data using the provided endpoints.
- Host: GitHub
- URL: https://github.com/ullaskunder3/meriadb-nodejs-restapi
- Owner: ullaskunder3
- Created: 2023-06-27T15:36:16.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T03:01:21.000Z (about 2 years ago)
- Last Synced: 2025-04-03T08:48:55.263Z (about 1 year ago)
- Topics: crud-api, db, expressjs, mariadb, thunderclient, vscode
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# User REST API
This API allows you to perform CRUD operations (Create, Read, Update, Delete) on user records stored in a MariaDB database.
## Base URL
```
http://localhost:3000
```
## Resources
### User
Represents a user record in the database.
#### Attributes
- `id` (integer): The unique identifier of the user.
- `name` (string): The name of the user.
- `email` (string): The email address of the user.
### Endpoints
#### Create a User
Create a new user record.
- URL: `/data`
- Method: `POST`
- Request Body:
```json
{
"name": "ullas kunder",
"email": "ullaskunder3@gmail.com"
}
```
- Response:
- Status: `201 Created`
- Body:
```json
{
"message": "Record created successfully"
}
```
#### Get All Users
Retrieve all user records.
- URL: `/data`
- Method: `GET`
- Response:
- Status: `200 OK`
- Body:
```json
[
{
"id": 1,
"name": "Monkey D luffy",
"email": "luffy@emperor.com"
},
{
"id": 2,
"name": "ullas kunder",
"email": "ullaskunder3@gmail.com"
},
...
]
```
#### Update a User
Update an existing user record.
- URL: `/data/:id`
- Method: `PUT`
- Request Body:
```json
{
"name": "Updated Name",
"email": "updated@example.com"
}
```
- Response:
- Status: `200 OK`
- Body:
```json
{
"message": "Record updated successfully"
}
```
#### Delete a User
Delete an existing user record.
- URL: `/data/:id`
- Method: `DELETE`
- Response:
- Status: `200 OK`
- Body:
```json
{
"message": "Record deleted successfully"
}
```
> Make sure rename .env-local to .env and replace current info with your db credientials
> If you are using Thunder Client, you can find the API collection provided in the project files.
make sure background db service is up and running
```
mysql -u root -p
```
Once you are logged in to the MariaDB server, execute the following command to display the list of existing databases:
```
show databases;
```
Create a new database named `user_restapi` by executing the following command:
```
create database user_restapi;
```
After creating the database, switch to the newly created database using the following command:
```
MariaDB [(none)]> use user_restapi
```
Creating the app_user Table
```
Database changed
MariaDB [user_restapi]> CREATE TABLE app_user(
-> id INT PRIMARY KEY AUTO_INCREMENT,
-> name VARCHAR(255) NOT NULL,
-> email VARCHAR(255) NOT NULL
-> );
Query OK, 0 rows affected (0.040 sec)
MariaDB [user_restapi]>
```
```
CREATE TABLE app_user (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL
);
```