Recently, I have been working on some code that allows me to retrieve data from an external API. Below is an example of the code:
//endpoint to fetch data from an external API
app.get("/externalapi", (req, res) => {
let apiURL = 'https://herokuapp.com/api/v1/data';
axios.get(apiURL)
.then(response => {
res.status(200).json(response.data);
})
.catch((err) => {
res.status(500).json({ message: err });
});
});
One of the sample data entries retrieved via Postman is shown below:
{
"data": [
{
"first_name": "Fiona",
"last_name": "Smith",
"phone_number": "987-3595-89",
"mental_health_referral": false,
"date_last_mental_health_referal": "02/09/2018T00:00:00.0000Z",
"legal_councel_referal": true,
"CHW_id": 6866318
},
{
"first_name": "Richard",
"last_name": "Stewart",
"phone_number": "281-0394-41",
"mental_health_referral": true,
"date_last_mental_health_referal": "03/23/2018T00:00:00.0000Z",
"legal_councel_referal": false,
"CHW_id": 9241074
},
{
"first_name": "Andrew",
"last_name": "Stevens",
"phone_number": "068-8173-37",
"mental_health_referral": true,
"date_last_mental_health_referal": "03/30/2018T00:00:00.0000Z",
"legal_councel_referal": true,
"CHW_id": 9241074
}
}
My current objective is to extract only Fiona's information, which is the first set of data. I have designed a URL template for this purpose:
GET https://herokuapp.com/api/v1/data/{{first_name}}/{{last_name}}/{{phone_number}}
I attempted to use the following URL:
https://herokuapp.com/api/v1/data?first_name=Fiona&last_name=Smith&phone_number=987-3595-89
However, I have not achieved the desired outcome. Even when I send the get request in Postman, it still returns all the results from the API. What could be the missing piece here?