The API recieves POST
requests to the link :
The parameters are send in the body of the POST request
body
of the POST has to have the following format :
interface Tweet {
tweetDate: string;
replies: { username: string; date: string }[];
likes: { username: string; date: string }[];
retweets: { username: string; date: string }[];
}
interface ApiResponse {
message: string;
responseBody: {
summary: {
timestamp: string;
engagementSpeed: number;
numberLikes: number;
numberReplies: number;
numberRetweets: number;
};
temperatureValues: { value: number }[];
engagementTypes: {
type: string;
timestamp: string;
username: string;
}[];
interactionIntervals: number[];
};
}
{
tweetDate: "1684156800000",
replies: [
{
username: "alice_wonderland",
date: "1684232400000",
},
{
username: "bob_builder",
date: "1684308000000",
},
{
username: "charlie_brown",
date: "1684383600000",
},
],
likes: [
{
username: "daisy_duke",
date: "1684459200000",
},
{
username: "edward_snowden",
date: "1684534800000",
},
],
retweets: [
{
username: "fiona_apple",
date: "1684610400000",
},
{
username: "george_clooney",
date: "1684686000000",
},
{
username: "hannah_montana",
date: "1684761600000",
},
],
}
const xhr = new XMLHttpRequest();
xhr.open("POST", "https://chirper-hcsu.onrender.com/api");
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
const body = JSON.stringify({
tweetDate: "1684156800000",
replies: [
{
username: "alice_wonderland",
date: "1684232400000",
},
{
username: "bob_builder",
date: "1684308000000",
},
{
username: "charlie_brown",
date: "1684383600000",
},
],
likes: [
{
username: "daisy_duke",
date: "1684459200000",
},
{
username: "edward_snowden",
date: "1684534800000",
},
],
retweets: [
{
username: "fiona_apple",
date: "1684610400000",
},
{
username: "george_clooney",
date: "1684686000000",
},
{
username: "hannah_montana",
date: "1684761600000",
},
],
});
xhr.onload = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(JSON.parse(xhr.responseText));
} else {
console.log(`Error: ${xhr.status} ${xhr.responseText}`);
}
};
xhr.send(body);
{
"message": "Temperature Values Ready",
"responseBody": {
"summary": {
"timestamp": "1684156800000",
"engagementSpeed": 1260,
"numberLikes": 3,
"numberReplies": 2,
"numberRetweets": 3
},
"temperatureValues": [
{
"value": 22
},
{
"value": 21.588104671871992
},
{
"value": 24.36150921919348
},
{
"value": 27.491210574410538
},
{
"value": 31.022981870562553
},
{
"value": 31.35541823867956
},
{
"value": 31.691416931633942
},
{
"value": 33.89690055694793
},
{
"value": 36.25586921046438
}
],
"engagementTypes": [
{
"type": "inital",
"timestamp": "1684156800000",
"username": "Initial Temperature"
},
{
"type": "reply",
"timestamp": "1684232400000",
"username": "alice_wonderland"
},
{
"type": "reply",
"timestamp": "1684308000000",
"username": "bob_builder"
},
{
"type": "reply",
"timestamp": "1684383600000",
"username": "charlie_brown"
},
{
"type": "like",
"timestamp": "1684459200000",
"username": "daisy_duke"
},
{
"type": "like",
"timestamp": "1684534800000",
"username": "edward_snowden"
},
{
"type": "retweet",
"timestamp": "1684610400000",
"username": "fiona_apple"
},
{
"type": "retweet",
"timestamp": "1684686000000",
"username": "george_clooney"
},
{
"type": "retweet",
"timestamp": "1684761600000",
"username": "hannah_montana"
}
],
"interactionIntervals": [
1260,
1260,
1260,
1260,
1260,
1260,
1260,
1260
]
}
}
The API returns this if :
The API returns this if :
Prerequisites Make sure you have the following installed on your machine:
Follow these steps to deploy the API on your local machine and visit it at http://localhost:8080.
Clone the API Repository:
git clone https://github.com/siyamthandandlovu/chirper.git
Navigate to the API Directory:
cd chirper
Install Dependencies:
npm install
Build TypeScript Code:
npm run build
Start the API Server:
npm start
By default, it should run on port 8080.
Visit Localhost:
Open your web browser and visit the following URL:
http://localhost:8080
You should now be able to interact with your TypeScript Node.js API locally.
You can use tools like Postman or Thunderclient to interact with the API endpoints.
Chirper is MIT Licensed.
I'm really open to suggestions on how to improve the API and its functions. I also developed a Next.js frontend component during the project, so I'm planning on releasing that soon and integrating it with the API.
In the meantime, if you have any suggestions/improvements, feel free to open an issure
Otherwise feel free to reach out to me on LinkedIn or by email.