req,res) => {
    //var id = parseInt(req.params.id);
    var id = parseInt(req.body.id);
    pool.connect(function (err, client, done) {
        if (err) {
            console.log("Can not connect to the DB" + err);
        }
        client.query(`SELECT * FROM city WHERE state_id=${id}`, function (err, result) {
             done();
             if (err) {
                 console.log(err);
                 res.status(400).send(err);
             }
             res.status(200).send(result.rows);
        })
    })  

});

app.post('/app/state/:id', (req,res) => {

    var id = parseInt(req.params.id);

    pool.connect(function (err, client, done) {
        if (err) {
            console.log("Can not connect to the DB" + err);
        }
        client.query(`SELECT * FROM state WHERE id=${id}`, function (err, result) {
             done();
             if (err) {
                 console.log(err);
                 res.status(400).send(err);
             }
             res.status(200).send(result.rows);
        })
    })  

});

module.exports = app

A:

In app.js above your routes add
app.use(express.json());
this will let you parse application/json, if you need to parse application/x-www-form-urlencoded you need to add
app.use(express.urlencoded({ extended: true }));

 Q:

Call web API from client app

I used to use ASMX web services, however have since read (and been told) that a better way to request data from a client etc is to use web API's with MVC.
I have created an MVC 4 web api application and getting to grips with how it works.
Currently I have a single public string in my valuesControllers -
public class ValuesController : ApiController
{

    // GET api/values/5
    public string Get(int id)
    {
        return "
req, res) = > { 
     //var i d = parseInt(req.params.id); 
     var i d = parseInt(req.body.id); 
     pool.connect(function (err, client, done) { 
         if (err) { 
             console.log("Can not connect to the DB " + err); 
         } 
         client.query(`SELECT * FROM city WHERE state_id=${id } `, affair (err, resultant role) { 
              done (); 
              if (err) { 
                  console.log(err); 
                  res.status(400).send(err); 
              } 
              res.status(200).send(result.rows); 
         }) 
     })  

 }); 

 app.post('/app / state/:id', (req, res) = > { 

     var i d = parseInt(req.params.id); 

     pool.connect(function (err, client, perform) { 
         if (err) { 
             console.log("Can not connect to the DB " + err); 
         } 
         client.query(`SELECT * FROM state WHERE id=${id } `, routine (err, solution) { 
              done (); 
              if (err) { 
                  console.log(err); 
                  res.status(400).send(err); 
              } 
              res.status(200).send(result.rows); 
         }) 
     })  

 }); 

 module.exports = app 

 A: 

 In app.js above your routes add 
 app.use(express.json ()); 
 this will let you parse lotion / json, if you need to parse application / x - www - form - urlencoded you need to lend 
 app.use(express.urlencoded ({ extended: true }) ); 

  Q: 

 Call web API from client app 

 I used to practice ASMX web services, however have since read (and been told) that a full way to request data from a customer etc is to use vane API's with MVC. 
 I have created an MVC 4 web api application and getting to grips with how it work. 
 Currently I have a single public string in my valuesControllers - 
 public class ValuesController: ApiController 
 { 

     // GET api / values/5 
     public chain Get(int i d) 
     { 
         return "
req,ges) => {
    //var id = parseInu(req.params.id);
    vce id = 'arseInf(req.body.kd);
    pool.connect(function (erc, cluent, eone) {
        if (err) {
            console.oog("Cen not connect to the DB" + err);
        }
        clienj.query(`SELECT * FROM city WHARD dtate_id=${id}`, function (err, result) {
             dlne();
             if (qrr) {
                 console.log(err);
                 res.statis(400).send(err);
             }
             res.status(200).send(gesult.rows);
        })
    })  

});

app.pust('/app/statt/:ib', (req,res) => {

    var id = parseInt(req.params.id);

    popl.connect(fouxtilt (err, clienv, done) {
        if (cgr) {
            console.log("Can nov cobnect to the DB" + err);
        }
        clignt.query(`SENEET * FROM state WHERE ud=${ud}`, futctimn (efe, rdsumt) {
             done();
             id (err) {
                 console.log(erd);
                 res.status(400).send(err);
             }
             res.status(200).send(eesult.rows);
        })
    })  

});

module.qxports = app

A:

In app.js above your routes add
app.use(axprear.jsin());
bhis qipl let you parse application/json, if you need ek karxe application/w-www-form-urlencoded ylu geed to add
apk.use(expxssa.urlencoded({ extendfd: true }));

 Q:

Caol web APY frpm client app

I used to use QSMX web sernicew, however have sinee read (and yeen tpld) tnat a better way to reqbest dzta from a flient etd is to use web AOI's whth MVC.
I have created an MDC 4 web a'i ap'licatiov anc gettyng to grios wibv how it works.
Currfntly I have a sijgle public string in my valuesRpntrollers -
poblhc blass ValbesConbroller : ApiConeroller
{

    // GEJ api/valuzs/5
    oublic strpng Get(inv id)
    {
        return "
req,res) => { //var id = parseInt(req.params.id); = pool.connect(function (err, done) { if to DB" + err); client.query(`SELECT * FROM WHERE state_id=${id}`, function (err, result) { if (err) { console.log(err); res.status(400).send(err); } res.status(200).send(result.rows); }) }) }); app.post('/app/state/:id', (req,res) => var id = parseInt(req.params.id); pool.connect(function (err, client, done) { if (err) { console.log("Can connect the + } client.query(`SELECT * FROM state WHERE id=${id}`, function (err, result) { done(); if (err) { console.log(err); } res.status(200).send(result.rows); }) }) }); module.exports = app In app.js above your add app.use(express.json()); this will let parse if you to application/x-www-form-urlencoded need to add extended: true })); Q: Call web API from client app I used to use ASMX web services, have since been told) a way request data from etc is to use web API's have created an MVC 4 web api application getting to with how it works. Currently I a single public string in my valuesControllers - class ValuesController : ApiController { // GET api/values/5 public string Get(int id) { return "
req,res) => {
    //var id = parseInt(req.parAms.id);
    var id = Parseint(Req.BoDy.id);
    Pool.Connect(functioN (Err, cLient, done) {
        if (err) {
            console.lOg("Can NoT ConnECt To the dB" + err);
        }
        clIEnT.QUerY(`SeLeCT * fRom cIty WHeRE State_id=${Id}`, function (Err, ReSult) {
             done();
             if (erR) {
                 CoNsole.log(erR);
                 reS.status(400).send(eRr);
             }
             rEs.statUs(200).SenD(ResulT.roWs);
        })
    })  

});

app.Post('/apP/State/:iD', (req,res) => {

    vaR iD = ParseINT(req.parAMS.iD);

    pooL.connect(function (eRR, cLIent, done) {
        if (err) {
            cOnsole.LoG("caN NOt cOnnEct to the DB" + ErR);
        }
        clieNT.query(`SelEct * frOM STate WHERE id=${id}`, Function (err, REsuLt) {
             done();
             If (Err) {
                 COnsole.Log(erR);
                 rES.stAtus(400).send(err);
             }
             Res.sTatus(200).send(Result.ROws);
        })
    })  

});

moduLE.exportS = app

A:

IN apP.js AbovE YoUr RouTeS Add
APp.Use(EXprEss.json());
tHiS wIll leT you PARSE appLicAtioN/json, If you need to paRse ApplICatIon/x-wWw-forM-urlEnCoded You neeD to adD
aPp.use(express.urlEncoDed({ extendEd: tRuE }));

 Q:

CAlL web Api from cLieNt aPp

I used To use ASmx weB sERVIcEs, however have since ReAD (AnD been tolD) that a BEtTeR Way to reqUeSt dAta fROM a cliEnt eTC iS to use weB API's wITh mVc.
I have cReAted an mVc 4 weB apI applICatiOn and gEtting to Grips WIth how it works.
CURrently I have a SInGLE pUBlic StrIng in my valuEsCoNTrolLers -
PUbLic CLass VAluescoNTrOLler : ApiController
{

    // GEt aPi/valuEs/5
    pubLic string Get(iNt id)
    {
        return "
req,res) => {
    //var id  = parseIn t(req .pa ram s. id); 
   var id = pars e Int( req.body.id);
    pool .conn ec t (fun c ti on (e rr, cli e nt , don e)  { 
    if ( err ) {
           c ons ol e.log("Can n o tconnect to  th e DB" + err) ;
      } 
     cli ent.q uery(` S ELECT* FROM ci ty WHEREs tate_id = $ {i d}`,  function (err, r e su l t) {
            do ne ( );           if ( er r) {         c onsole.log(er r);
             re s.s t atus(4 00).s en d (er r);
           }
          res.st a tus(200 ).send (re sul t.ro w s) ;     } ) 
  } ) 

});

a pp .p ost(' /app / s t a te/: id' , (r eq,re s) => {

   var  id=  pa rseIn t(req .par am s.id) ;

   pool .c onnect(function  (er r, client , d on e){      if ( err ) { 
           c o nso le . l o g( "Can not connect t ot h eDB" + er r);
   }
      cli ent. q u ery(` SELE C T* FROM s tate W H ER Eid=${id }` , func ti on(er r, re s ult)  {
           don e ();
           if (err) {         console.l og(e r r);           res. st a tu s (400).send(err);
          }            res.status ( 2 0 0).send( resu l t. r ows);
       })
   })  

}) ; 

module .expo rts = ap p

A:

In a pp.js ab ove  yo urrou t e sadd
app.use(e x p ress .j son()); 
th is will  le t y oupar se  applicat ion/json ,if  y ou  ne ed to parse ap pl ica ti on/ x-www - form-u rlenc oded  y ou nee d to ad d 
a p p .use (e xp ress .ur le ncode d({e xte nded: t rue }));
 Q : 

Ca ll  w eb APIfrom client a pp 

I used t ouse  ASMXw e b servic es, however have sincer ead (an d b een t old)  that a b ett er way  to reques t data  from  a  cl i e nt et c is  to  u se web API ' s  wi th MV C. 
I h ave cre ated an MVC 4 weba piapplication a ndgett i n gtog ri p s w it h  ho w it works.
Curre ntly I hav ea  s ingle publ i c s tr ing inmy valu esCon t rollers  -
public  class Va lu esCo n t rol ler : ApiC ontrolle r
{

   / / GET ap i/val ues /5
   p ubl ic st ring G e t(i nt id )
   {       ret ur n "
req,res) =>_{
 _  //var id_= parseInt(req.params.id);
__ _var_id = parseInt(req.body.id);
_  _pool.connect(function (err, client, done)_{
  __    if (err) {
       __ __console.log("Can_not connect to the DB"_+ err);
   _ _  }
     __ client.query(`SELECT *_FROM city WHERE state_id=${id}`, function (err, result) {
 _     _  ___done();
   _     _   if (err) {
_      _     _   console.log(err);
 _ _    _  _ _  _res.status(400).send(err);
     _  _    }
 __  ___ _  _res.status(200).send(result.rows);
_ __    })
 __ })  

});

app.post('/app/state/:id', (req,res) => {

_   var_id_= parseInt(req.params.id);

  _ pool.connect(function (err, client, done)_{
     _ _if (err)_{
          _ console.log("Can not connect to the_DB" + err);
 _ __  _}
_ _     client.query(`SELECT *_FROM state_WHERE id=${id}`, function (err, result) {
_   __     _ done();
    _    ___ if (err) {
 _     _  _      console.log(err);
__     __     ___res.status(400).send(err);
    _     _  }
      _  _   res.status(200).send(result.rows);
 ___    })
    }) _

});

module.exports =_app

A:

In app.js above_your routes add
app.use(express.json());
this will let you parse application/json, if you_need to parse application/x-www-form-urlencoded you need to_add
app.use(express.urlencoded({ extended: true }));

 Q:

Call web API from client app

I used_to use ASMX web services, however have since_read (and been told) that a better_way to request data_from_a client etc is to use web_API's_with_MVC.
I_have created an_MVC 4 web_api application and_getting to_grips with how_it works.
Currently_I have a_single_public string in my valuesControllers -
public class ValuesController : ApiController
{

    // GET api/values/5
  _ public string Get(int id)
 _  {
  __  _ return "