Skip to content

Latest commit

 

History

History
371 lines (252 loc) · 7.76 KB

README.md

File metadata and controls

371 lines (252 loc) · 7.76 KB

KoaCRUD


Translations


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:

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