Skip to content

Latest commit

 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upraised API

A RESTful API for managing gadgets with authentication.

Setup

  1. Install dependencies:
npm install
  1. Set up your environment variables in .env file:
DATABASE_URL="your_database_url"
JWT_SECRET="your_jwt_secret"
  1. Run the server:
# Default port (8080)
node src/index.js

Database Setup

Running PostgreSQL with Docker

  1. Make sure Docker is installed on your system

  2. Start the PostgreSQL container:

docker-compose up -d
  1. Verify the container is running:
docker ps
  1. To stop the container:
docker-compose down
  1. To view container logs:
docker-compose logs -f

The PostgreSQL container will be available at:

  • Host: localhost
  • Port: 5432
  • Database: devdb
  • Username: postgres
  • Password: devpass

Authentication

Create User

POST /auth/create_user
Content-Type: application/json

{
    "userName": "your_username",
    "password": "your_password"
}

Login

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>

Gadget Endpoints

Get All Gadgets

GET /gadgets
Authorization: Bearer <your_jwt_token>

# Optional query parameter
GET /gadgets?status=Available|Deployed|Destroyed|Decommissioned

Create a New Gadget

POST /gadgets
Authorization: Bearer <your_jwt_token>

Update Gadget

PATCH /gadgets
Authorization: Bearer <your_jwt_token>
Content-Type: application/json

{
    "name": "gadget_name",
    "status": "Available|Deployed|Destroyed|Decommissioned",
    "success": 0-100
}

Delete Gadget (Decommission)

DELETE /gadgets
Authorization: Bearer <your_jwt_token>
Content-Type: application/json

{
    "name": "gadget_name"
}

Self-Destruct Gadget

POST /gadgets/{id_of_gadget}/self-destruct
Authorization: Bearer <your_jwt_token>
Content-Type: application/json

{
    "confirmationCode": "your_confirmation_code"
}

Status Codes

  • 200: Success
  • 201: Created
  • 400: Bad Request
  • 401: Unauthorized
  • 422: Unprocessable Entity
  • 500: Internal Server Error

Response Format

All responses follow this format:

{
    "success": true|false,
    "message": "response message",
}

About

Phoenix api backend build with node, express and postgres

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages