api uber eat node js
Step 1: Install Required Packages
npm install express body-parser axios
Step 2: Set Up Express Server
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
Step 3: Set Up Uber Eats API Endpoints
const axios = require('axios');
const UBER_EATS_API_BASE_URL = 'https://api.ubereats.com/v1/';
app.post('/getRestaurants', async (req, res) => {
try {
const { location } = req.body;
const response = await axios.get(`${UBER_EATS_API_BASE_URL}feed`, {
params: { location },
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.post('/getMenu', async (req, res) => {
try {
const { restaurantId } = req.body;
const response = await axios.get(`${UBER_EATS_API_BASE_URL}restaurants/${restaurantId}/menu`);
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
Step 4: Handle Order Placement
app.post('/placeOrder', async (req, res) => {
try {
const { items, deliveryAddress } = req.body;
const response = await axios.post(`${UBER_EATS_API_BASE_URL}orders`, {
items,
deliveryAddress,
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
Step 5: Start the Server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});