Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it conceptually right to create a rest API using the post for every request?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading