2014년 12월 26일 금요일

[Express-js] REST: Get request and body JSON

according to http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods i want to manage request.body content using GET http method.

I am using express 4.

How to do it?

My index.is is:

var retrieve = function(req, res) {
  console.log("request", req.body);
};

var express = require('express');
var app = express();
var bodyParser = require('body-parser');

app.use(bodyParser.json()); // for parsing application/json

app.get('/retrieve', retrieve); 

app.listen(3000);



> according to http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods i want to manage request.body content using GET http method.
A GET request does not have a body. (You can send a body with any kind of request, but a body is supposed to have no meaning for GET requests, so it is not useful to send a body with a GET request.) If you want to send a body with your request and have it mean something, then you'll want to send a POST request or a PUT request.


댓글 없음:

댓글 쓰기