Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quiddlee/node-crud-api
๐ Node.js CRUD API | The Rolling Scopes School task
https://github.com/quiddlee/node-crud-api
crud-api mvc nodejs rest-api rs-school
Last synced: about 2 months ago
JSON representation
๐ Node.js CRUD API | The Rolling Scopes School task
- Host: GitHub
- URL: https://github.com/quiddlee/node-crud-api
- Owner: Quiddlee
- Created: 2024-01-29T08:26:57.000Z (11 months ago)
- Default Branch: develop
- Last Pushed: 2024-02-14T11:25:44.000Z (11 months ago)
- Last Synced: 2024-02-14T12:37:50.467Z (11 months ago)
- Topics: crud-api, mvc, nodejs, rest-api, rs-school
- Language: TypeScript
- Homepage:
- Size: 351 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Node CRUD API
*๐ฆฅ RS-School task.*
# Getting Started ๐
To run the project locally, you would have to download zip file with the repository or clone it to your computer. โจ## Setup and Running โ ๏ธ
What things do you need to do in order to run our project locally? ๐ค
* Use node 20 LTS โก
* Installed [.git](https://git-scm.com/) on your computer. โ๏ธ
* Code Editor of your choice. ๐
* Installed [npm](https://www.npmjs.com/). ๐ฆ## Installation And Preparation ๐ฎ
First make sure you have all the things listed in the previous section. Then clone our repository to your computer: ๐
```
git clone https://github.com/Quiddlee/node-crud-api.git
```or download zip file manually with our repository.
Navigate into project folder and run ๐ฆ:
```
npm install
```Create ```.env``` file in the root of the project and add all necessary variables ๐ฅ.
You can find ```.env.example``` as an example file in the project root or follow the lines below ๐บ:
```dotenv
PORT=YOUR_PORT
HOST=YOUR_HOST
```Finally run a development server: ๐คฉ
```
npm run start:dev
```
Aaaaand you're done! ๐๐ฅณ## Available Scripts ๐ฅ
Here you can find all the scripts that are available in our project. ๐ฆ
Start the app in `base` mode: โ
```
npm run start:dev
```Start the app in `multi` mode: ๐ชญ
```
npm run start:multi
```Start the app in `prod` mode: ๐ชถ
```
npm run start:prod
```Lint the app with `eslint`: ๐ฆ
```
npm run lint
```Lint adn fix the app errors with `eslint`: ๐จ
```
npm run lint:fix
```Format the App with **Prettier**: ๐งน
```
npm run format
```Format the App with **Prettier** fix: ๐
```
npm run format:fix
```Type check the App with **TypeScript**: ๐ฆ
```
npm run type-check
```Run unit-tests with **Vitest**: ๐งช
```
npm run test
```
# Working with API ๐ณ
In the project root folder, you can find a Postman collection that will make your life easier while working with the API. ๐![postman.jpg](./public/postman.jpg)
## API endpoints ๐ฆ
The API has the following endpoints:| Method | Endpoint | Description |
|---------|:--------------:|------------------------------------:|
| GET | /users | Get all the users from the database |
| GET | /users/:id | Get a single user by ID |
| POST | /users | Create a new user in the database |
| PUT | /users/:id | Update a user by ID |
| DELETE | /users/:id | Delete a user by ID |## Request body ๐ฅ
| Endpoint | Body | Example |
|----------|:----------:|----------------------------------------------------------------------------------------------------------------------------:|
| POST | /users | An object with the username age and hobbies ```{"username": "user", "age": 20, "hobbies": ["cooking", "sport"]}``` |
| PUT | /users/:id | An object with the updated username age and hobbies ```{"username": "updated user", "age": 30, "hobbies": ["updated hobbie"]}``` |## Response format ๐
| Field | Type | Description |
|---------|:-------------------:|-----------------------------------------------------------------------------:|
| status | "success" or "fail" | Indicates whether the request was successful or not |
| message | string | in case of failed result the response will contain message why it is failed |
| data | Object or Array | The data returned by the request |## Response examples ๐
**GET /users**
```json
{
"status": "success",
"data": {
"users": [
{
"username": "user",
"age": 20,
"hobbies": ["cooking", "sport", "programming"]
},
{
"username": "user2",
"age": 21,
"hobbies": ["sport", "programming"]
},
{
"username": "user3",
"age": 22,
"hobbies": ["hobbie"]
}
]
}
}
```**GET /users/:id Error case**
```json
{
"status": "fail",
"message": "๐ฏ User not found"
}
```