5
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.

1
  • 1
    I don't quite follow what the issue is here... you're not getting req.params.resourceUri? Or not able to send the response in correct format as Manuel hinted? Commented Jul 10, 2013 at 11:52

5 Answers 5

10

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...
    });

};
Sign up to request clarification or add additional context in comments.

1 Comment

Let me know if this does not answer your question.
2

On your app.js:

url: http://localhost:3000/params?param1=2357257&param2=5555

var app = express();
app.get('/params', function (req,res) {

        // recover parameters

    var param1=req.query.param1;
    var param2=req.query.param2;

    // send params to view index.jade   
    var params = {
        param1: param1,
        param2: param2
        };
    res.render('index.jade', {parametros: parametros});             
 });

At index.jade to recover values:

p= params.param1

p= params.param2

Comments

1

you're probably searching for this: http://expressjs.com/api.html#res.json

so it would be

res.json(pricingDetail);

Comments

1

encode your url passed as parameter :

vm%2Fhpcloud%2Fnova%2Fstandard.small

Used site : http://meyerweb.com/eric/tools/dencoder/

Comments

0

Not use string, if you need to get this use and id or readable string, '/path/my-article' not '/path/my article'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.