Search code examples
javascriptnode.jsexpressapi-key

Node JS web service based on api key


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?


Solution

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