I'm developing a rest API that, once you've bought a paid plan and received an apiKey, you can create a maximum of a certain number of apps depending on the paid plan chosen. I'm using node.js and to handle requests I'm using HTTPS module like this:
https.createServer(options, (req, res) => {
res.writeHead(200);
req.on('data', function (data) {
let command = data.toString();
var cmd = utils.getCommand(command);
var cmdResult = "";
switch (cmd.method) {
case 'SIGNIN':
cmdResult = auth.signin(cmd.parameters[0], cmd.parameters[1], cmd.parameters[2]);
break;
case 'LOGIN':
cmdResult = auth.login(cmd.parameters[0], cmd.parameters[1], cmd.parameters[2]);
break;
}
res.end(result.getResult(cmdResult));
});
}).listen(11200);
For debugging I'm using curl like this:
curl -X POST 'SIGNIN|username|password|apikey' https://mycurrentipaddress:11200
The above command performs a signin to add a new app that using the API; the authentication work with the apiKey
the API will offer an authentication service, a noSQL DB based on JSON and push notifications.
Was my idea and its current realization conceptually correct? or it doesn't make sense?
No, that isn't REST, you should read this for a better understanding of that pattern.
That doesn't mean it won't work, but it's not a conventional pattern, which I think is what you're looking for.
There are any number of tutorials on the internet on how to write a RESTful API, just take the time to follow some. Also, I'd also strongly suggest starting with a framework like ExpressJS rather than the Node standard libraries, you'll have plenty of opportunity to learn those in the future, starting with a framework is a much better path for learning, imo.