You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
968 B

3 years ago
const http = require('http')
const url = require('url');
function json_response(code, object, response) {
response.statusCode = 200;
response.setHeader('content-type', 'Application/json');
response.end(JSON.stringify(object));
}
const server = http.createServer(function (request, response) {
parsedUrl = url.parse(request.url, false);
if(request.method === "POST") {
console.log('POST');
if(parsedUrl.query.param)
{
json_response(200,parsedUrl.query,response);
}
else
{
json_response(400,{error:"missing required param"},response);
}
}
else if(request.method === "PUT") {
console.log('PUT');
json_response(200,{status : "where should I put it ?"},response);
}
else if(request.method === "DELETE") {
console.log('DELETE');
json_response(200,{status : "no delete available"},response);
}
else
{
json_response(200,{status : "active"},response);
}
});
server.listen(8080);