const http = require ( 'http' ); const studentDetails = { Id : '01' , Name : 'Zaahid' , Semester : 5 , Batch : 2023 }; const server = http . createServer (( req , res ) => { if ( req . method === 'GET' ) { res . end ( studentDetails ); console . log ( "GET" ) } else if ( req . method === 'POST' ) { let body = '' ; req . on ( 'data' , ( chunk ) => { body += chunk ; }); req . on ( 'end' , () => { res . end ( `POST request received with data: ${ body } ` ); }); } else if ( req . method === 'PUT' ) { let body = '' ; req . on ( 'data' , ( chunk ) => { body += chunk ; }); req . on ( 'end' , () => { res . end (...
Comments
Post a Comment