This is the documentation for the Storefront API, which allows you to manage users, products, and orders.
-
Create a user with the following command
-
Create the main database
-
Create the testing database
-
Grant all privileges on the main database to the store_user
-
Grant all privileges on the testing database to the store_user
Create a .env
file in the root directory of the project and add the following configurations:
PORT=3000 NODE_ENV=dev POSTGRES_HOST=127.0.0.1 POSTGRES_PORT=5432 POSTGRES_DB=storefront POSTGRES_DB_TEST=storefront_test POSTGRES_USER=store_user POSTGRES_PASSWORD=password BCRYPT_PASSWORD=speak-friend-and-enter SALT_ROUNDS=10 TOKEN_SECRET=this-is-a-secret-token
Make sure to install the following dependencies using npm:
npm install prettier eslint db-migrate nodemon jasmine bcrypt dotenv express express-rate-limit helmet jsonwebtoken morgan pg supertest uuid
-
/api/users
- POST: Create a new user.
- Endpoint:
http://localhost:3000/api/users
- Request body:
{ "user_name": "example", "firstname": "example", "lastname": "example", "password": "example" }
- Endpoint:
- POST: Create a new user.
-
/api/users/authenticate
- POST: Authenticate a user and retrieve a token.
- Endpoint:
http://localhost:3000/api/users/authenticate
- Request body:
{ "user_name": "example", "password": "example" }
- Endpoint:
- POST: Authenticate a user and retrieve a token.
-
/api/products
- GET: Get all products.
- Endpoint:
http://localhost:3000/api/products
- Endpoint:
- GET: Get all products.
-
/api/orders
- POST: Create a new order.
- Endpoint:
http://localhost:3000/api/orders
- Request body:
{ "user_id": "user_id", "status": "example" }
- Endpoint:
- POST: Create a new order.
-
Create User
- HTTP Method: POST
- Endpoint:
http://localhost:3000/api/users
- Request body:
{ "user_name": "example", "firstname": "example", "lastname": "example", "password": "example" }
-
Authenticate User
- HTTP Method: POST
- Endpoint:
http://localhost:3000/api/users/authenticate
- Request body:
{ "user_name": "example", "password": "example" }
-
Update User
-
HTTP Method: PATCH
-
Endpoint:
http://localhost:3000/api/users/{user_id}
-
Request body:
{ "id": "user_id", "user_name": "example", "firstname": "example", "lastname": "example" }
Note: Don't forget to include the token in the request headers for authorization.
-
-
Get All Users
- HTTP Method: GET
- Endpoint:
http://localhost:3000/api/users
- Request headers:
Note: Replace
Authorization: Bearer {token}
{token}
with the actual token received from user authentication.
-
Delete User
-
HTTP Method: DELETE
-
Endpoint:
http://localhost:3000/api/users/{user_id}
-
Request body:
{ "user_name": "example", "password": "example" }
Note: Don't forget to include the token in the request headers for authorization.
-
Similar CRUD operations can be performed for Products and Orders by using the respective endpoints mentioned above.
Column | Type | Nullable | Default |
---|---|---|---|
id | uuid | not null | uuid_generate_v1() |
user_name | character varying(60) | ||
firstname | character varying(60) | not null | |
lastname | character varying(60) | not null | |
password | character varying(300) | not null |
Indexes:
- "users_pkey" PRIMARY KEY, btree (id)
- "users_user_name_key" UNIQUE CONSTRAINT, btree (user_name)
Column | Type | Nullable | Default |
---|---|---|---|
id | uuid | not null | uuid_generate_v1() |
name | character varying(60) | ||
price | character varying(60) | not null |
Indexes:
- "products_pkey" PRIMARY KEY, btree (id)
- "products_name_key" UNIQUE CONSTRAINT, btree (name)
Column | Type | Nullable | Default |
---|---|---|---|
id | uuid | not null | uuid_generate_v1() |
user_id | character varying(60) | not null | |
status | character varying(200) | not null |
Indexes:
- "orders_pkey" PRIMARY KEY, btree (id)