Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrekuratomi/koacrud
API for users CRUD. This app uses the programming language Javascript, its framework Koa.js, the database SQLite3 the APIs documenter Swagger and the test libs Mocha and Chai.
https://github.com/andrekuratomi/koacrud
javascript koa mocha-chai sqlite3 swagger
Last synced: 29 days ago
JSON representation
API for users CRUD. This app uses the programming language Javascript, its framework Koa.js, the database SQLite3 the APIs documenter Swagger and the test libs Mocha and Chai.
- Host: GitHub
- URL: https://github.com/andrekuratomi/koacrud
- Owner: AndreKuratomi
- Created: 2023-04-21T19:13:12.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-01T14:55:33.000Z (3 months ago)
- Last Synced: 2024-11-01T15:32:27.620Z (3 months ago)
- Topics: javascript, koa, mocha-chai, sqlite3, swagger
- Language: JavaScript
- Homepage:
- Size: 446 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## KoaCRUD
- [Description](#description)
- [Instalation](#instalation)
- [How to use](#how-to-use)
- [Terms of use](#terms-of-use)
- [References](#references)
## Translations
- [🇬🇧 / 🇺🇸 English](https://github.com/AndreKuratomi/KoaCRUD)
- [🇧🇷 Português brasileiro / Brazilian portuguese](./.multilingual_readmes/README_pt-br.md)
## Description
KoaCRUD is an API that manages users, its registrations, listings, updates and deletions. This app uses the programming language Javascript, its framework Koa.js, the database SQLite3 the APIs documenter Swagger and the test libs Mocha and Chai.
## Instalation
0. It is first necessary to have instaled the following devices:
- The code versioning [Git](https://git-scm.com/downloads),
- A code editor, also known as IDE. For instance, [Visual Studio Code (VSCode)](https://code.visualstudio.com/),
- A client API REST program. [Insomnia](https://insomnia.rest/download) or [Postman](https://www.postman.com/product/rest-client/), for instance,
- Javascript's runtime enviroment [Node.js](https://nodejs.org/en/download/package-manager),
- And Node.js' package manager [NPM](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):```
npm install -g npm
```
1. Clone the repository KoaCRUD by your machine terminal or by the IDE:
```
git clone https://github.com/AndreKuratomi/KoaCRUD.git
```WINDOWS:
Obs: In case of any mistake similar to this one:
```
unable to access 'https://github.com/AndreKuratomi/KoaCRUD.git': SSL certificate problem: self-signed certificate in certificate chain
```Configure git to disable SSL certification:
```
git config --global http.sslVerify "false"
```Enter the directory:
```
cd KoaCRUD
```Open your app for your IDE:
```
code .
```Install its dependencies:
```
npm install
```
WINDOWS:In case any error similar to the one bellow be returned:
```
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\KoaCRUD\\lorem\\ipsum\\dolor\\etc'
HINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths
```Run cmd as adminstrador with the following command:
```
reg.exe add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f
```And run the application:
```
npm run dev
```The app will run with local server localhost: or the default port 3000. Write after it the application routes or endpoint's as we are going to see bellow.
For running the app's tests use the following command:
```
npm test
```
2. After everything installed we need to create our enviroment variable .env:
```
touch .env
```Inside it we need to define our enviroment variable PORT:
```
PORT=port
```Obs: the .env infos cannot be shared! The arquive is already at .gitignore for not being pushed to the repository.
## How to use
After everything is well installed use your API Client for the following routes:
Routes
Registration:
User Registration (POST method): /user (or localhost:3000/user)
Example to be used as requisition body:
```
{
"age": "32",
"cpf": "00000000000",
"email": "[email protected]",
"nome": "João da Silva"
}
```And the expected response:
```
Status: 201 CREATED
``````
{
"message": "Data added successfully!"
}
```In case of underage user registration the expected answer must be:
```
Status: 403 UNAUTHORIZED
``````
{
"message": "Unauthorized! Users under 18 are not allowed."
}
```User listing:
Registered users listing (GET method): /users (or localhost:3000/users)
Example to be used as requisition body:
```
(No body requisition)
```And the expected response:
```
Status: 200 OK
``````
[
{
"id": 1,
"age": "32",
"cpf": "00000000000",
"email": "[email protected]",
"nome": "João da Silva"
}
]
```User listing by id:
User listing data (GET method): /user/id** (ou localhost:3000/users/id**)
\*\*fill with the previously registerd user id.
Example to be used as requisition body:
```
(No body requisition)
```And the expected response:
```
Status: 200 OK
``````
[
{
"id": 1,
"age": "32",
"cpf": "00000000000",
"email": "[email protected]",
"nome": "João da Silva"
}
]
```In case user is not found by id the expected answer must be:
```
Status: 404 NOT FOUND
``````
{
"message": "User not found!"
}
```User update:
User data update (PATCH method): /user/id** (or localhost:3000/users/id**)
\*\*fill with the previously registerd user id.
Only the 'age' and 'email' fields can be updated.
Example to be used as requisition body:
```
{
"age": 35
}
```In case the user is already registered in SQLite the response will be:
```
Status: 200 OK
``````
{
"message": "User successfully updated!"
}
```Otherwise the response will be:
```
Status: 404 NOT FOUND
``````
{
"message": "User not found!"
}
```If neither "age" nor "email" fields will be used the response will be:
```
Status: 400 BAD REQUEST
``````
{
""message": "Invalid params! Must be or age or email or both!"
}
```User deletion:
User registered deletion (DELETE method): /user/id** (or localhost:3000/users/id**)
\*\*fill with the previously registerd user id.
Example to be used as requisition body:
```
(No body requisition)
```In case the user is already registered in SQLite the response will be:
```
Status: 204 NO CONTENT
``````
(No body requisition)
```Otherwise the response will be:
```
Status: 404 NOT FOUND
``````
{
"message": "User not found!"
}
```Swagger:
API documentation by Swagger: /swagger (or localhost:3000/swagger)
## Terms of use
This API is only for didatic purposes, not commercial.
## References
- [Chai](https://www.chaijs.com/guide/)
- [Dotenv](https://www.npmjs.com/package/dotenv)
- [Koa.js](https://koajs.com/)
- [Mocha](https://mochajs.org/api/mocha)
- [Node.js](https://nodejs.org/en/)
- [Nodemon](https://nodemon.io/)
- [NPM](https://www.npmjs.com/)
- [SQLite3](https://www.sqlite.org/index.html)
- [Swagger](https://editor.swagger.io/)