How to pass string variable as parameter to REST API call using node js

node.js

Solution

Assuming node.js and express.js.

Register a route with your application.

server.js:

...
app.get('/myservice/:CustomerId', myservice.queryByCustomer);
....

Implement the service using the `req.params` for the passed in Id.

routes/myservice.js:

exports.queryByCustomer = function(req, res) {
    var queryBy = req.params.CustomerId;
    console.log("Get the data for " + queryBy);
    // Some sequelize... :)
    Data.find({
        where : {
        "CustomerId" : parseInt(queryBy)
        }
    }).success(function(data) {
        // Force a single returned object into an array.
        data = [].concat(data);
        console.log("Got the data " + JSON.stringify(data));
        res.send(data);  // This should maybe be res.json instead...
    });

};

Problem

``` var express = require('express'); var app = express(); // Get Pricing details from subscription app.get('/billingv2/resourceUri/:resourceUri', function(req, res) { var pricingDetail = {} pricingDetail.resourceUri = req.params.resourceUri; pricingDetail.chargeAmount = '25.0000'; pricingDetail.chargeAmountUnit = 'per hour'; pricingDetail.currencyCode = 'USD'; res.send(pricingDetail); // send json response }); app.listen(8080); ``` I need to call the above API using the string parameter `vm/hpcloud/nova/standard.small`. Please note that `vm/hpcloud/nova/standard.small` is a single string param.

Original source