javascript - Is there any node.js tutorials for implementing restapi and auth using ONLY core modules? -
javascript - Is there any node.js tutorials for implementing restapi and auth using ONLY core modules? -
i have task implement simple web server rest interface , user authorization without using third-party frameworks 99% tutorials can find start using restify/express/something else. , it's hard available in core modules , functionality utilize implement what's been reqested (never used node.js before).
upd: heres did if helps someone: https://github.com/danilaml/simplerestserver
this pretty good. simple walk through. i'm doing same thing assignment. https://gist.github.com/shimondoodkin/6213581. have post , 404
'use strict'; var http = require('http'); var server = http.createserver(function(req, res) { if (req.url === '/hello') { res.writehead(200, { 'content-type': 'application/json' }); if (req.method === "post") { console.log('post'); var body = ''; req.on('data', function(data) { body += data.tostring('utf-8'); }); req.on('end', function(data) { body += info ? data.tostring('utf-8') : ''; var parsedbody; seek { parsedbody = json.parse(body); } catch(e) { console.log(e); res.write(json.parse({msg: 'invalid json'})); homecoming res.end(); } res.write(json.stringify({msg: 'hello ' + parsedbody.name})); res.end(); }); } else { res.write(json.stringify({msg: 'hello world'})); res.end(); } } else { res.writehead(404, { 'content-type': 'application/json' }); res.write(json.stringify({msg: 'could not find page'})); res.end(); } }); server.listen(3000, function() { console.log('server started'); });
javascript node.js rest restful-authentication restful-url
Comments
Post a Comment