Skip to content

This code sets up a RESTful API using Express in Node.js for managing security controls, including functionalities to add, update, and delete controls, with data stored in memory and presented in a web interface with Bootstrap.

Notifications You must be signed in to change notification settings

MiguelAngelHorta/API-Server

Repository files navigation

API-Server

This code sets up a RESTful API using Express in Node.js for managing security controls, including functionalities to add, update, and delete controls, with data stored in memory and presented in a web interface with Bootstrap.

Architecture Local App frontend + backend

Setup Instructions

Prerequisites

Steps to Run the App

  1. Clone the repository to your local machine:

    git clone https://github.com/MiguelAngelHorta/Security-Controls-Inventory.git
  2. Navigate to the project directory:

    cd Security-Controls-Inventory
  3. Install dependencies:

    npm install express body-parser cors 
  4. Start the Express server:

    node appAPI.js
  5. The server will start running at http://localhost:3000. The JSON data in the inventory table can be viewed @ 'http://localhost:3000/controls' in the browser.

iScreen Shoter - 20240323121144041

iScreen Shoter - Google Chrome - 240323145703

  1. Interact with the frontend by opening folder in Visual Studio and opening the 'indexAPI.html' file through

iScreen Shoter - 20240323145504663

  1. Interact with the backend server through bash through the following commands

    (go to folder)

     cd <folder location>

    (add a control)

    curl -X POST -H "Content-Type: application/json" -d '{"mainID":"5", "mainDescription":"Sample Control",        "domain":"Sample Domain", "scope":"Yes"}' http://localhost:3000/controls

    (update a control)

    curl -X PUT -H "Content-Type: application/json" -d '{"mainDescription":"Updated Control",     
    "domain":"Updated Domain", "scope":"No"}' http://localhost:3000/controls/5

    (delete a control)

    curl -X DELETE http://localhost:3000/controls/5

Testing the APIs with Postman

iScreen Shoter - 20240323121615435

Summary of JavaScript Functions

  • fetchControls(): Fetches all controls from the server and populates the table.
  • AddData(): Adds a new control to the server and updates the table.
  • updateData(id): Fetches data of a specific control for editing.
  • updateControl(id): Updates the data of a specific control on the server and in the table.
  • deleteControl(id): Deletes a specific control from the server and updates the table.

Git commits from Visual Studio to Github

  • go to folder with files
  • $cd foldername
  • Initialize git
  • $git init
  • add files
  • $git add .
  • commit changes
  • $git commit -m 'message'
  • verify remote URL (if not already done)
  • $git remote -v
  • Pull Changes from remote repo to synchronize local with Github (if applicable)
  • $git pull --rebase origin main -Resolve diverged branches (if applicable)
  • $git config pull.ff only
  • Pull changes from the remote repository again
  • $git pull --rebase origin main
  • push changes
  • $git push -u origin main

About

This code sets up a RESTful API using Express in Node.js for managing security controls, including functionalities to add, update, and delete controls, with data stored in memory and presented in a web interface with Bootstrap.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published