How do I receive a post or get request with typescript?

1

I'm starting with nodejs now and would like to use typescript to program compiling for pure javascript. So I'm having trouble finding something succinct so I can understand (since I'm a PHP programmer) how to receive post and get requests. For example, in PHP I use this:

$_POST["foo"] or file_get_contents("php://input") using angular and angularjs

or

$_GET["foo"]

Can you help me?

    
asked by anonymous 20.11.2017 / 01:03

1 answer

1

You can use node.js and express.js to get post and get.

Install the expression in this way:     npm install express

declare a variable to receive express ()

var express = require('express');
var app = express();

use the function below to receive the GET request

app.get('/SuaView.extensão', (req, resp) => {

    //Seucódigo
            resp.render("SuaView");
            resp.end();
        });

And just below you have the POST request

app.post('/SeuPost', (req, resp) => {

    //SeuCódigo

        resp.render("SuaView");
        resp.end();
});

resp.render renders the view you want, if you are manipulating some information, you can create a variable that takes a function and fills an object. To pass it to the view, you can do this: resp.render ("SuaView", {NewVariable: objDaFunction});

    
24.11.2017 / 13:58