Create a controller to make a GET type request

Asked

Viewed 98 times

0

I am creating a simple API with Ode that I do a news post, in this I am using express to create my routes of my application, I have already managed to create a controller that posts my news, but I do not know how a controller would do to get.. someone could help me??

  • If you’ve ever made a route to a POST, what is the difficulty in creating one for the method GET? Post your code to make it easier to demonstrate what needs to be done on it.

2 answers

1


If Voce is using express, you should use the get function and point to a function of your controller that lists your news. Something more or less like this:

app.get('/', (req, res) => res.send( #COLOCA AQUI A FUNÇÃO QUE LISTA SUAS NOTICIAS ))

0

Follow the code of my route GET:

const express = require('express');
const User = require('../Models/index');

const router = express.Router();

router.get('timeline', (req, res) => {
    res.send({ req.params.User});
});

but from what I saw in that way would not be right to do right?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.