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

string パラメータを使用して上記の API を呼び出す必要がありますvm/hpcloud/nova/standard.smallvm/hpcloud/nova/standard.small単一の文字列パラメーターであることに注意してください。

4

5 に答える 5

10

node.js と express.js を想定しています。

アプリケーションにルートを登録します。

サーバー.js:

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

req.params渡された Id のを使用してサービスを実装します。

ルート/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...
    });

};
于 2013-09-24T19:48:37.880 に答える
1

パラメータとして渡された URL をエンコードします。

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

使用サイト: http: //meyerweb.com/eric/tools/dencoder/

于 2014-10-27T20:39:05.137 に答える
1

あなたはおそらくこれを探しているでしょう: http://expressjs.com/api.html#res.json

そうなるだろう

res.json(pricingDetail);
于 2013-07-10T11:47:47.413 に答える