Skip to content

Commit

Permalink
Add new endpoint for adding two numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
akbast committed Jul 2, 2024
1 parent afaf63a commit ee48824
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import express from 'express';
const app = express();
const PORT = process.env.PORT || 3000;

// Middleware to parse incoming request bodies
app.use(express.json());

// Sample array of YouTube video URLs for demonstration
const videoUrls = [
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
Expand All @@ -19,6 +22,19 @@ app.get('/videos', (req, res) => {
res.status(200).json(videoUrls);
});

// New POST endpoint to add two numbers
app.post('/addNumbers', (req, res) => {
const { num1, num2 } = req.body;
// Validate that both inputs are numbers
if (typeof num1 !== 'number' || typeof num2 !== 'number') {
return res.status(400).json({ error: 'Both inputs must be numbers' });
}
// Calculate the sum
const sum = num1 + num2;
// Return the sum in a JSON response
res.json({ sum });
});

app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

0 comments on commit ee48824

Please sign in to comment.