Skip to content

ana-kop/quiz_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Documentation for the API

This is a technical guide for the API created for the CEGE0043 final assessment apps. The API used for the apps is a RESTful API, which is defined as "an architectural style for an application program interface (API) that uses HTTP requests to access and use data." - link to the source

Table of Contents

  1. System Requirements
  2. Deployment
  3. Testing
  4. File description
  5. Code reference

1. System Requirements

See the README.md for the apps.

2. Deployment

Procedures to deploy the app:

  1. Open a terminal window for the Ubuntu server and enter your password.
  2. Type the following command: cd /home/studentuser
  3. Create a certs folder in the this directory, and add a file called postGISConnection.js in this folder, which is structured as follows:
    host: [your host IP address],
    user: [your user id],
    database: ucfscde,
    password: [your password],
    port: 5432
  1. Clone the source code of this question setting app from Github by typing the following two commands (where studentuser is your UCL id):
cd /home/studentuser/code
git clone https://github.com/ana-kop/quiz_app -b master
  1. Clone the source code of the corresponding Node JS server from Github by typing the following two commands (where studentuser is your UCL id):
cd /home/studentuser/code
git clone https://github.com/ana-kop/quiz_api -b master
  1. Start the Node JS server by typing the following commands in the terminal:
cd /home/studentuser/code/quiz_api 
pm2 start dataAPI.js

3. Testing

Procedures to test this app:

  1. Make sure your device is connected to UCL Wifi or UCL VPN.
  2. Make sure the Node JS server is active.
  3. To see if there are any errors on the API side, you could inspect the errors on the server side; to do so, enter the debug mode through the command line window by typing:
cd /home/studentuser/code/quiz_api 
node dataAPI.js

4. File descriptions

The files associated with the API are located in several sub-folders.

~/quiz_api:

  • dataAPI.js: The main .js file of this API, using which the API can launched from the command line.

  • ~/routes : Contains further Javascript files required by the API.

    • crud.js: contains the calls required for the four basic operations that can be performed on database applications: Create, Read, Update, and Delete.
    id description
    crud.get('/getUserId', Call to get user id from the database.
    crud.post('/insertQuizPoint', Call to insert the new question data into the database.
    crud.post('/deleteQuestion', Call to delete a specified question from the database.
    crud.post('/insertQuizAnswers', Call to insert the new answer data into the database.
    • crud.js: contains the GET calls required for accessing the exisiting data from the database and sending it to the client.
    id description
    geoJSON.get('/questionsAddedWithinLastWeek', Gets the data for the loadQuestionsThisWeek function.
    geoJSON.get('/fiveDifficultQuestions/', Gets the data for the loadDifficultQuestions function.
    geoJSON.get('/fiveClosestQuestions/:latitude/:longitude', Gets the data for the loadFiveClosestQuestions function.
    geoJSON.get('/dailyParticipationRatesAll/', Gets the data for the loadParticipationAllGraph function.
    geoJSON.get('/dailyParticipationRates/:user_id', Gets the data for the loadParticipationUserGraph function.
    geoJSON.get('/topFiveScorers/', Gets the data for the loadTopScorersGraph function.
    geoJSON.get('/geoJSONUserId/:user_id', Gets the data for the loadYourQuestions function.
    geoJSON.get('/userQuestions/:user_id', Gets the data for the correctAnswers function.
    geoJSON.get('/userRanking/:user_id', Gets the data for the getRanking function.
    geoJSON.get('/lastFiveQuestionsAnswered/:user_id', Gets the data for the loadLastQuestions function.
    geoJSON.get('/questionsNotAnswered/:user_id', Gets the data for the loadUnansweredQuestions function.
    geoJSON.get('/allQuestions/', Gets the data for the loadAllQuestions function.
  • package-lock.json: this file is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates. This file is intended to be committed into source repositories.

Code reference

  • A large proportion of code here is adapted from the examples provided in class for CEGE0043 Web and Mobile and GIS by Claire Ellul, including:
    • Basic structure of bootStrap.html;
    • Restful API for the main database operations, create, read, update and delete.
    • Siginificant parts of this README.md file (from the technical-documentation-example file provided with the material for this assignment.)
  • This readme file was created using online editor
  • Other minor components of the code used for these apps were taken from a number of sources that are referenced in the specific code files.

About

REST API for the quiz app

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published