Reputation: 141
I have some web services, written in node js and express. I want to use api key based service. Suppose I currently have a web service "getRooms".
app.get('/getRooms/', function (req, res) {
'use strict';
N.API.getRooms(function (rooms) {
res.send(rooms);
},function (err) {
res.send(err);
});
});
I am using it by calling https://xxxxxx/getRooms. Now I want to use https://xxxxxx/APIKEY/getRooms. This APIKEY is different for different clients. So how do I modify my web services to achieve this?
Upvotes: 3
Views: 1045
Reputation: 5666
You can modify it as /APIKEY/getrooms
to achieve the desired result. However it would be better it you send APIKEY
in request header but obviously it depends on your case.
Upvotes: 4
Reputation: 2093
you can modify your code like this
app.get('/getRooms?api_key=xxxx', function (req, res) {
console.log(req.query.api_key) // print xxxx when user request to https://xxxxxx/getRooms/APIKEY
});
Upvotes: 0