Skip to content

Personality Test App API built on Java17, Javalin, ORMLite, Moshi and MariaDB. Check README.md for documentation

Notifications You must be signed in to change notification settings

fourthperson/personality_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Personality Test API

Simple Personality-Test REST API for the Personality Test App built on Java17, Javalin Web Framework, ORM Lite, Jackson, and MariaDB

Introduction

The API receives and returns only JSON application/json.

Each response JSON body has a status key which is an integer and a data key which contains the data pertaining to that response.

Status value 200 means Success, with the requested information in the data key.
Status value 500 means that an error occurred, and it will return a string description of the error under the data key.

Database Setup

This application uses MariaDB There is a dockerfile included and an exported SQL File pers_test_2022-09-27.sql.

  1. Install docker
  2. Run docker compose up, to spin up a MariaDb and PhpMyAdmin container.
  3. Access PhpMyAdmin by visiting localhost:8080 on your browser
  4. Use the pers_test database
  5. Import the pers_test_2022-09-27.sql file or copy its contents to import the questions.

Run the app

Run the Main.java file, and you can access the routes/endpoints in REST clients at http://localhost:3030

Routes

Questions (GET)

/questions

Used to fetch a list of simple personality-test questions.

Request

Send a standard GET request to the /questions endpoint with no payload or body data.

Response

Returns JSON with an array of 20 questions under the data key


{
    "status": 200,
    "data": [
        {
            "id": 1,
            "text": "I prefer one-on-one conversations to group activities",
            "created_on": "2022-09-26 13:58:06"
        },
        {
            "id": 2,
            "text": "I often prefer to express myself in writing",
            "created_on": "2022-09-26 13:58:19"
        },
        {
            "id": 3,
            "text": "I seem to care about wealth, fame, and status less than my peers",
            "created_on": "2022-09-26 13:58:37"
        }
    ]
}

Evaluate (POST)

/evaluate

Used to evaluate the user's answers. Accepts input in JSON format. Content-Type has to be application/json when calling this request with a JSON body.

Request

The incoming JSON Body for the request should be as follows:


{
    "answer_count": 5,
    "answers": "true;false;true;true;true"
}

where answer_count is the number of questions that the user answered, and answers is a concatenated string of "true" and "false" answers to the questions, separated by a semicolon;.
Any spaces in the answers string will be removed.

Response

Returns the result of the analysis.


{
    "status": 200,
    "data": "Introverted"
}

About

Personality Test App API built on Java17, Javalin, ORMLite, Moshi and MariaDB. Check README.md for documentation

Topics

Resources

Stars

Watchers

Forks

Languages