RandomDial is a random phone number generator designed to generate random phone numbers for a telecommunications company. It is a simple and easy-to-use REST API that provides users with the ability to do the following:
- Generate Random 10-digits phone numbers starting with zero. Users can generate single or multiple numbers (maximum of 500 at a time).
- View the list of phone numbers generated and the corresponding total.
- Sort the list of phone numbers generated in ascending or descending order as well as view the maximum and minimum phone numbers in the list.
- Clear the list of phone numbers generated from the storage
The following needs to be installed on your system to setup up the application:
The following steps can be taken to setup this application locally
git clone https://github.com/JCanaks/RandomDial.git
cd randomdial
Run the following command to create an env file using the example env file provided
cp .env.example .env
You can now update the values for the env variables used in the application
npm install
Run the following command to start the application:
npm start
To start the application in development mode, please run:
npm run dev-start
You have now successfully set up the application 🎉🎉. Navigate to http://localhost:3000/
to access the API on port 3000
. The port number can be configured by specifying a value in the PORT
variable in your .env file (The port value will default to 3000
if none is specified).
To run tests locally, run the following command:
npm test
The following are the API features and endpoints for the application which can be tested via Postman or any other API testing tool.
POST /phonenumbers
- Generates a single or multiple phone numbers (The amount to be generated should be specified in the request body).
Request Body
{
"amount": 5
}
Response
{
"message": "5 phone number(s) successfully generated",
"data": {
"total": 5,
"phoneNumbers": [
"0786409991",
"0560095760",
"0525790942",
"0356922965",
"0132715892"
]
}
}
GET /phonenumbers
- Returns a list of all phone numbers generated and the corresponding total.
Response
{
"message": "Phone Numbers Fetched Successfully",
"data": {
"total": 5,
"phoneNumbers": [
"0786409991",
"0560095760",
"0525790942",
"0356922965",
"0132715892"
]
}
GET /sort?order=<sort-order>
- Returns a list of phone numbers sorted in ascending or descending order as well as the maximum and minimum phone number on the list. A query parameter 'order'
should be specified with the value 'asc'
or 'ascending'
to get the list in ascending order (e.g. GET /sort?order=asc
) while 'desc'
or 'descending'
should be specified to get the list in descending order (e.g. GET /sort?order=desc
)
Response
Ascending order
{
"message": "Phone Numbers Fetched Successfully",
"data": {
"total": 5,
"min": "0132715892",
"max": "0786409991",
"phoneNumbers": [
"0132715892",
"0356922965",
"0525790942",
"0560095760",
"0786409991"
]
}
}
Descending order
{
"message": "Phone Numbers Fetched Successfully",
"data": {
"total": 5,
"min": "0132715892",
"max": "0786409991",
"phoneNumbers": [
"0786409991",
"0560095760",
"0525790942",
"0356922965",
"0132715892"
]
}
}
DELETE /clear
- Removes (clears) all generated phone numbers in the storage.
Response
{
"message": "Phone Numbers Successfully deleted",
"data": {}
}
Click here to view the API documentation generated for this application with Postman.
- Jane C. Anaekwe - @JCanaks