The helper method for handling JSON Post and Get requests.
13141
def _handle_wrapper(self):
    """"""
    if self.request.headers.get("X-Requested-With") != "XMLHttpRequest":
      logging.error("Got JSON request with no X-Requested-With header")
      self.response.set_status(
          403, message="Got JSON request with no X-Requested-With header")
      return

    self.json_response.clear()
    try:
      self.handle()
    except errors.MissingYamlError:
      logging.debug("Could not find 'mapreduce.yaml' file.")
      self.json_response.clear()
      self.json_response["error_class"] = "Notice"
      self.json_response["error_message"] = "Could not find 'mapreduce.yaml'"
    except Exception, e:
      logging.exception("Error in JsonHandler, returning exception.")
      # TODO(user): Include full traceback here for the end-user.
      self.json_response.clear()
      self.json_response["error_class"] = e.__class__.__name__
      self.json_response["error_message"] = str(e)

    self.response.headers["Content-Type"] = "text/javascript"
    try:
      output = json.dumps(self.json_response, cls=json_util.JsonEncoder)
    # pylint: disable=broad-except
    except Exception, e:
      logging.exception("Could not serialize to JSON")
      self.response.set_status(500, message="Could not serialize to JSON")
      return
    else:
      self.response.out.write(output)
1253449
async def receive_json(self, content: typing.Dict, **kwargs):
        
        # TODO assert format, if does not match return message.
        request_id = content.pop('request_id')
        action = content.pop('action')
        await self.handle_action(action, request_id=request_id, **content)
673349
def rest_post(url, data, timeout, rethrow_exception=False):
    ''''''
    try:
        response = requests.post(url, headers={'Accept': 'application/json', 'Content-Type': 'application/json'},\
                                 data=data, timeout=timeout)
        return response
    except Exception as e:
        if rethrow_exception is True:
            raise
        print('Get exception {0} when sending http post to url {1}'.format(str(e), url))
        return None
680868
def handleHttpPost(request, endpoint):
    
    if request.mimetype and request.mimetype != MIMETYPE:
        raise exceptions.UnsupportedMediaTypeException()
    request = request.get_data()
    if request == '' or request is None:
        request = '{}'
    responseStr = endpoint(request)
    return getFlaskResponse(responseStr)
537557
def make_post_request(self, url, auth, json_payload):
        """"""
        response = requests.post(url, auth=auth, json=json_payload)
        return response.json()
1032081
function returnJSON(finalResp, res) {
    if (JSONformat === 'JSON') {
      res.set('Content-Type', `application/json; charset=${encoding}`);
      res.json(finalResp);
    } else {
      res.set('Content-Type', `text/plain; charset=${encoding}`);
      res.send(JSON.stringify(finalResp));
    }
  }
89058
def handle_post(core, request, params)
      payload = params['payload'] || request.body.read
      dispatch(core, request, *params['splat'], payload)
    rescue JSON::ParserError
      [400, 'Invalid JSON payload']
    end
262255
def post(self, path, data=None, json_data=None, params=None):
        """"""
        r = requests.post(url=self.url + path, data=data, json=json_data, params=params, timeout=self.timeout)
        try:
            r.raise_for_status()
        except requests.exceptions.HTTPError:
            raise SwitcheoApiException(r.json()['error_code'], r.json()['error_message'], r.json()['error'])
        return r.json()
422819
function json (request) {

    var type = request.headers.get('Content-Type') || '';

    if (isObject(request.body) && type.indexOf('application/json') === 0) {
        request.body = JSON.stringify(request.body);
    }

    return function (response) {

        return response.bodyText ? when(response.text(), function (text) {

            var type = response.headers.get('Content-Type') || '';

            if (type.indexOf('application/json') === 0 || isJson(text)) {

                try {
                    response.body = JSON.parse(text);
                } catch (e) {
                    response.body = null;
                }

            } else {
                response.body = text;
            }

            return response;

        }) : response;

    };
}
927334
function handleGetRequest(request) {
  const objId = request.objectId;
  const className = request.className;
  if (objId) {
    // Object.fetch() query
    const collection = getCollection(className);
    const currentObject = collection[objId];
    if (!currentObject) {
      return Parse.Promise.as(respond(404, {
        code: 101,
        error: 'object not found for update',
      }));
    }
    let match = _.cloneDeep(currentObject);

    if (match) {
      const toOmit = Array.from(getMask(className));
      match = _.omit(match, toOmit);
    }

    return Parse.Promise.as(respond(200, match));
  }
  const data = request.data;
  indirect = data.redirectClassNameForKey;
  let matches = recursivelyMatch(className, data.where);
  let matchesClassName = '';
  if (indirect) {
    matches = outOfBandResults.matches;
    if (outOfBandResults.className) {
      matchesClassName = outOfBandResults.className;
    }
  }

  if (request.data.count) {
    return Parse.Promise.as(respond(200, { count: matches.length }));
  }

  matches = queryMatchesAfterIncluding(matches, data.include);

  const toOmit = Array.from(getMask(className));
  matches = matches.map((match) => _.omit(match, toOmit));

  // TODO: Can we just call toJSON() in order to avoid this?
  matches.forEach(match => {
    if (match.createdAt) {
      match.createdAt = match.createdAt.toJSON();
    }
    if (match.updatedAt) {
      match.updatedAt = match.updatedAt.toJSON();
    }
  });

  // sort results if necessary
  if (data.order && data.order.length > 0 && matches.length > 0) {
    matches = sortQueryresults(matches, data.order);
  }

  const limit = data.limit || DEFAULT_LIMIT;
  const startIndex = data.skip || 0;
  const endIndex = startIndex + limit;
  const response = { results: matches.slice(startIndex, endIndex) };

  // Add the class name for the outgoing objects to the response if sepcified
  if (matchesClassName.length > 0) {
    response.className = matchesClassName;
  }

  return Parse.Promise.as(respond(200, response));
}
1226429
def _post_json(path, object_to_post)
      resp = @rawclient.post(url(path), JSON.dump(object_to_post), {'Content-type' => 'application/json'})
      JSON.parse(resp.content)
    end
1307226
function handler(req, res) {

        var path = cog.getConfig('options.api_data');
        var urlRegex = cog.getConfig('options.api_url_regex');
        var url = req.url.replace(/^\//, '').replace(/\/$/, '');

        console.log(req.method + ' ' + req.url);

        // Find the JSON-data file and serve it, if URL points to the API.
        if (path && urlRegex && urlRegex.test(url)) {
            var file = path + '/' + url + '.json';
            if (grunt.file.exists(file)) {
                res.end(grunt.file.read(file));
                return;
            }
        }

        if (req.method == 'POST') {
            // TODO: This needs fixing, since it throws an error.
            res.end('{"message": "OK"}');
        }

    }
418756
def _prepare_request_json(self, kwargs):
        """"""

        # Check for python keywords in dict
        kwargs = self._check_for_python_keywords(kwargs)

        # Check for the key 'check' in kwargs
        if 'check' in kwargs:
            od = OrderedDict()
            od['check'] = kwargs['check']
            kwargs.pop('check')
            od.update(kwargs)
            return od
        return kwargs
579385
public static JSONObject getJSONObject(HttpPost request, Integer method, HashMap<String, String> params) throws JSONException {
        switch (method) {
        case METHOD_PUT:
        case METHOD_DELETE:
        case METHOD_POST:
            return doPostRequest(request, params);
        default:
            throw new RuntimeException("Wrong http method requested");
        }
    }
527704
def post(url, parameters = {})
      response = connection.post do |req|
        req.url "#{api_endpoint}#{url}"
        req.headers['Content-Type'] = 'application/json'
        req.body = parameters.to_json
      end
      on_complete(response)
      response
    end
199004
def json(
    body,
    status=200,
    headers=None,
    content_type="application/json",
    dumps=json_dumps,
    **kwargs
):
    
    return HTTPResponse(
        dumps(body, **kwargs),
        headers=headers,
        status=status,
        content_type=content_type,
    )
958160
protected BaseResponse executePost(String url, String json) {
        return executePost(url, json, null);
    }