parent
5bf63fd9f2
commit
c7632b060d
@ -0,0 +1,37 @@
|
||||
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);
|
Loading…
Reference in new issue