Express.js supports the following routing methods:

1. GET: Used to retrieve data from a server.
Example:
app.get(‘/’, (req, res) => {
res.send(‘Hello World!’);
});

2. POST: Used to submit data to a server.
Example:
app.post(‘/’, (req, res) => {
const data = req.body;
res.send(data);
});

3. PUT: Used to update data on a server.
Example:
app.put(‘/’, (req, res) => {
const data = req.body;
res.send(data);
});

4. DELETE: Used to delete data from a server.
Example:
app.delete(‘/’, (req, res) => {
const data = req.body;
res.send(data);
});

5. PATCH: Used to modify data on a server.
Example:
app.patch(‘/’, (req, res) => {
const data = req.body;
res.send(data);
});

6. HEAD: Used to retrieve header information from a server.
Example:
app.head(‘/’, (req, res) => {
res.send(‘OK’);
});

7. OPTIONS: Used to send a list of HTTP methods supported by a server.
Example:
app.options(‘/’, (req, res) => {
const methods = [‘GET’, ‘POST’, ‘PUT’, ‘DELETE’, ‘PATCH’, ‘HEAD’, ‘OPTIONS’];
res.send(methods);
});

Leave a Reply

Your email address will not be published. Required fields are marked *