Skip to content

Predictive text Hapi API with a single GET endpoint. The single endpoint returns the t9 predictive text interpretation of a given integer number. I use a Trie class with a pre-loaded dictionary for implementation.

Notifications You must be signed in to change notification settings

dboland77/phoneword-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This is the backend for the t9 phoneword React frontend.

The API implements a number to word converter in the style of an old T9 mobile phone.

For example given the input 23 the output will be ad,ae,af,bd,be,bf,cd,ce,cf.

It uses "Brute Force" to do this - just iterating through all possible combinations.

Enhanced:

  1. I have enhanced this to use prediction via a pre-loaded dictionary.

  2. I use a prefix-tree (Trie) data structure to implement the word filtering

  3. I use a file stream to read the dictionary.txt file

To run

  1. Clone this repo
  2. In the project folder run npm install to install the package dependencies. Please check peer dependencies
  3. The code uses ECMAScript so please make sure that your node version is >= 14
  4. The API will run at localhost: 4000
  5. The API takes one query parameter called num which will be interpreted to text. For example: localhost:8000/?num=322

Testing

  1. API endpoint was tested with various values of the input parameter
  2. API endpoint tested directly in the URL bar
  3. Also tested using Postman
  4. Manual testing of the frontend

Stack

  1. Node.js
  2. Hapi.js

Notes / Issues

  1. On installing Hapi through npm I got 5 high severity vulnerabilities. I checked the links for more info and it say that all versions of hapi are vulnerable to DOS due to the CORS request handler having a vulnerability.

  2. I removed this package and installed @hapi/hapi ... this is "hapi-er"

Assumptions

  1. That I have a word list available (for now I have hardcoded this in a text file)

Limitations

  1. Only one word will be interpreted. If you enter multiple words separated by spaces this will not work.

  2. This is not production ready in any way shape or form. It is a skeleton prototype to prove it works.

  3. Not so much as a 404 is provided if anything goes wrong

Future improvement

  1. The API could be extended to interpret full messages

  2. Case sensitivity could be introduced

  3. The word list could be provided by API, or database rather than hardcoded

  4. For deployment it would need: Authorisation, Testing, caching, better error handling (Boom plugin) , validation, cookies, process monitoring (Good plugin)

  5. env variables and API setup for production not considered here - just localhost.

  6. The models folder should contain relevant schema (for database objects mapped to http GET/POST/PUT/DELETE)

  7. Very basic testing has been performed this would need full testing.

  8. My Trie class can implement auto-complete but this is not turned on.

About

Predictive text Hapi API with a single GET endpoint. The single endpoint returns the t9 predictive text interpretation of a given integer number. I use a Trie class with a pre-loaded dictionary for implementation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages