A RESTful API for managing gadgets with authentication.
- Install dependencies:
npm install- Set up your environment variables in
.envfile:
DATABASE_URL="your_database_url"
JWT_SECRET="your_jwt_secret"
- Run the server:
# Default port (8080)
node src/index.js
-
Make sure Docker is installed on your system
-
Start the PostgreSQL container:
docker-compose up -d- Verify the container is running:
docker ps- To stop the container:
docker-compose down- To view container logs:
docker-compose logs -fThe PostgreSQL container will be available at:
- Host: localhost
- Port: 5432
- Database: devdb
- Username: postgres
- Password: devpass
POST /auth/create_user
Content-Type: application/json
{
"userName": "your_username",
"password": "your_password"
}POST /auth/login
Content-Type: application/json
{
"userName": "your_username",
"password": "your_password"
}Response includes a JWT token that should be used in the Authorization header for protected routes:
Authorization: Bearer <your_jwt_token>
GET /gadgets
Authorization: Bearer <your_jwt_token>
# Optional query parameter
GET /gadgets?status=Available|Deployed|Destroyed|DecommissionedPOST /gadgets
Authorization: Bearer <your_jwt_token>PATCH /gadgets
Authorization: Bearer <your_jwt_token>
Content-Type: application/json
{
"name": "gadget_name",
"status": "Available|Deployed|Destroyed|Decommissioned",
"success": 0-100
}DELETE /gadgets
Authorization: Bearer <your_jwt_token>
Content-Type: application/json
{
"name": "gadget_name"
}POST /gadgets/{id_of_gadget}/self-destruct
Authorization: Bearer <your_jwt_token>
Content-Type: application/json
{
"confirmationCode": "your_confirmation_code"
}- 200: Success
- 201: Created
- 400: Bad Request
- 401: Unauthorized
- 422: Unprocessable Entity
- 500: Internal Server Error
All responses follow this format:
{
"success": true|false,
"message": "response message",
}