You must have the following installed to use UserParser API:
To use this API, you'll need to follow these steps:
-
In your terminal window, navigate to UserParser API:
cd ~/YOUR_PROJECTS_DIRECTORY/user-parser-api/. -
In your terminal, run
npm installornpm ito install all the required packages. -
Create a
.envfile in the root directory of UserParser API and create a variable callPORT. Your file should look like this: PORT=3000 -
Run
npm run startto compile the typescript files viatscand to start the server. (you can usenpm run devany time after this since everything will already be compiled in/dist/)
Once the server is running, you can send a POST request to either of the available endpoints
The two available endpoints are:
- localhost:3000/api/v1/parser
- localhost:3000/api/v2/parser
UserParser API expects a JSON object in the request body that follows this convention:
{
"data": "JOHN0000MICHAEL0009994567"
}You can send this via Postman by:
- Creating a new request to one of UserParser API's endpoints and setting that request to POST.
- Pasting the JSON object above into the body and selecting raw.
- Finally change the data type from text to JSON in the dropdown menu to the right.
Alternatively, you can paste this cURL into your terminal instead of using Postman:
curl --location --request POST 'localhost:3000/api/v1/parse' \
--header 'Content-Type: application/json' \
--data-raw '{
"data": "JOHN0000MICHAEL0009994567"
}'The response object will look like this for the v1 endpoint:
{
"statusCode": 200,
"data": {
"firstName": "JOHN0000",
"lastName": "MICHAEL000",
"clientId": "9994567"
}
}And like this for the v2 endpoint:
{
"statusCode": 200,
"data": {
"firstName": "JOHN",
"lastName": "MICHAEL",
"clientId": "999-4567"
}
}