Using NodeJS, write an API that accepts a post request with a UTF-8 string payload and returns a ROT-13 version of the string, storing the original string in a database of your choice (SQLite, MongoDB, PostgreSQL/MySQL). The API should be capable of accepting a string of 1,000 characters. Then provide an alternate implementation using Ruby on Rails. (No 3rd party libraries or gems may be used for ROT-13.)
To get a local copy up and running follow these simple steps.
Node v14.17.5
Express v4.18.1
MongoDB
Mongoose v6.4.1
Jest v29.2.2
- body-parser
- dotenv
- nodemon
-
Clone the repo and cd into it sh git clone https://github.com/salmanali23/rot13.git
-
Move into the project directory
cd rot13
-
Install dependencies
yarn
-
Start the server
yarn run start
yarn run dev
run with nodemon watch
- Run test suits
yarn jest
- A simple api application to convert the given string to ROT13
- First check whether rotation of string is in db or not.
- If is then simply return the encryption in db
- If not the create hash of each character with it's ROT-13 version on runtime and replace each character of original string
- After this original and rot13 strings are saved in db
- API Error Handling added at application level
- Functional test added in
encrypt.spec.js
file
- Method: POST
- URL: https://API_BASE_URL/api/v1/string_rotation
for running local it would become
http://localhost:5000/api/v1/string_rotation
{ "stringRotation": { "originalString": "This is a test message" } }
{ "stringRotation": { "originalString": "This is a test message", "rotString": "Guvf vf n grfg zrffntr" } }