Middleware to serve JSON at the index route eg. a request to / will return data/index.json
171629
function interceptIndex(request, response, next) {
	if (args.index === true && request.path === '/') {
		request.path = '/index.json';
	}
	return next();
}
983350
def with_json(self, data=None, **params):
        
        if isinstance(data, (tuple, list)):
            data = dict(data)

        if params:
            # data must be None or able to be a dict
            if isinstance(data, dict):
                data.update(params)
            elif data is None:
                data = params
            else:
                raise ValueError('Data must be None or a dict if used with params, got: %r' % data)

        req = self.with_headers({'Content-Type': 'application/json', 'Accept': 'application/json'})
        if isinstance(data, basestring):
            # Looks like it's already been encoded
            return req.with_body(data)
        else:
            return req.with_body(json.dumps(data))
447270
function json(url, callback) {
    return request(url, function(req) {
      if (req.responseText) callback(JSON.parse(req.responseText));
    }, "application/json");
  }
1201359
function view_json(req, src, options, end) {
    load(src
        , {
            authorization: req.headers['authorization'],
            X_Forwarded_For: req.X_Forwarded_For
        }

        , function(status, result) {
            if (status !== true) {
                return end(false, 'status > ' + status);
            };

            result.get(['json'], function(status, data) {
                if (status == true) {
                    if (options.yaml) {
                        data = yaml.safeDump(data, {indent: options.yaml});
                    } else {
                        data = JSON.stringify(data, null, "\t");
                    };

                } else {
                    data = 'status > ' + status;
                };

                end(status, data);
            });
        }
    );
}
954051
function handleQueryParameters(request, response, next) {
	if (args.query === true && Object.keys(request.query).length > 0) {
		request.path += '/' + Object.keys(request.query).join('_') + '.json';
	}
	return next();
}
1193731
def index(request, obj_id):
    """"""
    if request.method == 'GET':
        return get(request, obj_id)
    elif request.method == 'PUT':
        getPutData(request)
        return put(request, obj_id)
795521
def handle(self, environ, start_response):
        ""
        # Pass off to the router
        try:
            handler = self.route(
                environ['PATH_INFO'].lower(),
                environ['REQUEST_METHOD'].lower(),
            )
            if handler is None:
                raise HttpNotFound()
        # Handle errors
        except HttpNotFound:
            start_response('404 Not Found', [('Content-Type', 'application/json')])
            return [json.dumps({"error": "not_found"})]
        except HttpMethodNotAllowed:
            start_response('405 Method Not Allowed', [('Content-Type', 'application/json')])
            return [json.dumps({"error": "method_not_allowed"})]
        # Dispatch to the named method
        body = environ['wsgi.input'].read()
        if body:
            body = json.loads(body)
        response = handler(
            environ['PATH_INFO'].lower(),
            body,
        )
        # Send the response
        start_response('200 OK', [('Content-Type', 'application/json')])
        return [json.dumps(response)]
968211
function middlewareFunction (req,res,next){

  return ipToLocation(req.ip)
    .then(function (location) {
      req.location = location;
      next();
    })
    .catch(function (error) {
      req.locationError = error;
      next();
    })

}
1164585
async def request(self, method, path, json=None, auth=True):
        """"""
        url = 'http://{}/api/'.format(self.host)
        if auth:
            url += '{}/'.format(self.username)
        url += path

        try:
            async with self.websession.request(method, url, json=json) as res:
                if res.content_type != 'application/json':
                    raise ResponseError(
                        'Invalid content type: {}'.format(res.content_type))
                data = await res.json()
                _raise_on_error(data)
                return data
        except client_exceptions.ClientError as err:
            raise RequestError(
                'Error requesting data from {}: {}'.format(self.host, err)
            ) from None
700888
function(req, res, next) {
    // If we timed out before managing to respond, don't send the response
    if (res.headersSent) {
      return;
    }

    // Look for `.json` or `.xml` extension in path
    // And override request accept header
    if (/.json$/.test(req.path)) {
      req.headers.accept = 'application/json';
    } else if (/.xml$/.test(req.path)) {
      req.headers.accept = 'application/xml';
    }

    // Use request accept header to determine response content-type
    res.format({
      json: function() {
        res.status(res.code).jsonp(res.data);
      },
      xml: function() {
        var xml;
        try {
          var xmlData = JSON.parse(JSON.stringify(res.data));
          xml = this.xmlBuilder.buildObject(xmlData);
          res.set('Content-Type', 'application/xml; charset=utf-8');
          res.status(res.code).send(xml);
        } catch (e) {
          res.status(500).end();
        }
      }.bind(this)
    });
  }
775196
def _json_request(self, method, path, data):
        

        response = self._request(method, path, data=data)
        _raise_for_status(response)
        if len(response.data) > 0:
            return _json_from_response(response)
        return response.data
640416
function defineRoute (server, opts) {

    server.route({
        method: 'GET',
        path: '/bomb',
        handler: handler,
        config: {
            jsonp: 'callback',
            validate: {
                query: {
                    count: Hapi.types.Number()
                },
                payload: false
            }
        }
    });

    function handler (req) {
        var count = (req.query.count || opts.defaultBombCount);
        var res = {};
        res[opts.plural] = _.sample(opts.things, count);
        req.reply(res);
    }

}
1280658
function mockServer(app) {
        const jsonRouter = jsonServer.router(db);

        const shouldMockReq = req => {
          return (
            req.method !== "GET" ||
            (req.headers.accept &&
              req.headers.accept.indexOf("application/json") !== -1)
          );
        };

        if (serverOpts.delay) {
          app.use((req, res, next) => {
            if (shouldMockReq(req)) {
              return pause(serverOpts.delay)(req, res, next);
            }
            return next();
          });
        }

        app.use(jsonServer.rewriter(rewrites));

        // user defined routers
        app.use(jsonServer.bodyParser);

        // user query normalizr
        app.use((req, res, next) => {
          if (shouldMockReq(req)) {
            req.query = toJsonServer(req.query);
            return next();
          }
          return next();
        });

        routers.forEach(router => app.use(router));

        // json server router
        app.use((req, res, next) => {
          if (shouldMockReq(req)) {
            return jsonRouter(req, res, next);
          }
          return next();
        });

        return app;
      }
513631
def _update_request(self, data, options):
        
        data = json.dumps(data)

        if 'headers' not in options:
            options['headers'] = {}

        options['headers'].update({'Content-type': 'application/json'})

        return data, options
180722
public ActionFuture<IndexResponse> sendDataAsync(
            String jsonSource, String index, String type, String id) {
        return indexQueryAsync(buildIndexRequest(jsonSource, index, type, id));
    }
89314
def post_json(self, uri, data, **kwargs):
        
        encoded_data = json.dumps(data)
        kwargs.setdefault("headers", {}).update({
            "Content-Type": "application/json",  # tell server we are sending json
        })
        return self.post(uri, data=encoded_data, **kwargs)
609838
function (routerMiddelware, req, res, next) {
		var middlewareFilename = routerMiddelware.split('.')[0];
		var middlewareFunction = routerMiddelware.split('.')[1];

		if (!req.pipa) req.pipa = {};

		this.middlewares[middlewareFilename][middlewareFunction](req, res, function (data) {
			_.extend(req.pipa, data); next();
		});
	}