logoEframix

Routing

Learn how to define routes in your Eframix application.

Routing Overview

Eframix allows you to define routes for handling HTTP requests. Below are examples of how to handle different HTTP methods:

GET Request

The `GET` method is used to retrieve data from the server. Below is an example of how to define a `GET` route:

app.get('/', (req, res) => {
res.end('Home Page');
});

In this example, the root route ('/') responds with the text "Home Page".

GET Request - About Page

You can also define additional `GET` routes like this:

app.get('/about', (req, res) => {
res.end('About Page');
});

Here, the `/about` route will return "About Page" when accessed.

POST Request

The `POST` method is used to send data to the server. Below is an example of how to define a `POST` route:

app.post('/api/data', (req, res) => {
res.json({ message: 'Data received' });
});

In this example, when data is sent to the `/api/data` route, the server responds with a JSON object confirming receipt.

These examples demonstrate how to define routes for different HTTP methods and paths. Feel free to explore and customize your routes based on your application needs.