Send an HTTP GET request to the newton API
    operation: one of the API endpoints
    expression: the str for the given endpoint to evaluate
354302
def send_request (operation, expression):
    
    
    base = 'https://newton.now.sh'
    url = '%s/%s/%s' % (base, operation, urllib.parse.quote(expression))
    
    with urllib.request.urlopen(url) as response:
        return handle_response(response)
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)
1293102
def parse_endpoint(endpoint, identifier_type=None):
        
        # compute the operation
        parts = endpoint.split(".")
        operation = Operation.from_name(parts[1])

        # extract its parts
        matcher = match(operation.endpoint_pattern, endpoint)
        if not matcher:
            raise InternalServerError("Malformed operation endpoint: {}".format(endpoint))
        kwargs = matcher.groupdict()
        del kwargs["operation"]
        if identifier_type is not None:
            kwargs["identifier_type"] = identifier_type
        return operation, Namespace(**kwargs)
149226
def get(self, url, data=None, params=None):
        
        return self.request("get", url, data, params)
580818
def endpoint(url, methods=['GET']):
  
  def decorator(function, methods=methods):
    # Always allow OPTIONS since CORS requests will need it.
    methods = set(methods)
    methods.add('OPTIONS')

    @wraps(function)
    def wrapper(environment, start_response):
      try:
        start_time = time.time()

        if function.func_name not in (_serving_mode_endpoints
                                      [settings.serving_mode]):
          start_response('403 Forbidden',
                         [('Content-Type', 'application/json')])
          return marshal.dumps({
            ERRORS_FIELD: ['kronosd is configured to block access to this '
                           'endpoint.'],
            SUCCESS_FIELD: False,
            TOOK_FIELD: '%fms' % (1000 * (time.time() - start_time))
          })
        req_method = environment['REQUEST_METHOD']

        # If the request method is not allowed, return 405.
        if req_method not in methods:
          start_response('405 Method Not Allowed',
                         [('Allow', ', '.join(methods)),
                          ('Content-Type', 'application/json')])
          return marshal.dumps({
            ERRORS_FIELD: ['%s method not allowed' % req_method],
            SUCCESS_FIELD: False,
            TOOK_FIELD: '%fms' % (1000 * (time.time() - start_time))
          })

        headers = []
        remote_origin = environment.get('HTTP_ORIGIN')

        if req_method == 'OPTIONS':
          # This is a CORS preflight request so check that the remote domain is
          # allowed and respond with appropriate CORS headers.
          # http://www.html5rocks.com/static/images/cors_server_flowchart.png
          if is_remote_allowed(remote_origin):
            headers.extend([
              ('Access-Control-Allow-Origin', remote_origin),
              ('Access-Control-Allow-Credentials', 'true'),
              ('Access-Control-Allow-Headers', ', '.join(
                ('Accept', 'Content-Type', 'Origin', 'X-Requested-With'))),
              ('Access-Control-Allow-Methods', ', '.join(methods))
            ])
          # We just tell the client that CORS is ok. Client will follow up
          # with another request to get the answer.
          start_response('200 OK', headers)
          return ''

        # All POST bodies must be json, so decode it here.
        if req_method == 'POST':
          try:
            environment['json'] = marshal.loads(environment['wsgi.input']
                                                .read())
          except ValueError:
            start_response('400 Bad Request',
                           [('Content-Type', 'application/json')])
            return marshal.dumps({
              ERRORS_FIELD: ['Request body must be valid JSON.'],
              SUCCESS_FIELD: False,
              TOOK_FIELD: '%fms' % (1000 * (time.time() - start_time))
            })

        # All responses are JSON.
        headers.append(('Content-Type', 'application/json'))

        if remote_origin:
          headers.append(('Access-Control-Allow-Origin', remote_origin))

        response = function(environment, start_response, headers)
        if not isinstance(response, types.GeneratorType):
          response[TOOK_FIELD] = '%fms' % (1000 * (time.time() - start_time))
          response = marshal.dumps(response)
        return response
      except Exception, e:
        log.exception('endpoint: uncaught exception!')
        start_response('400 Bad Request',
                       [('Content-Type', 'application/json')])
        return marshal.dumps({
          ERRORS_FIELD: [repr(e)],
          SUCCESS_FIELD: False,
          TOOK_FIELD: '%fms' % (1000 * (time.time() - start_time))
        })

    if settings.profile:
      wrapper = profile(wrapper)

    # Map the URL to serve to this function. Only map certain
    # endpoints if serving_mode is restrictive.
    global ENDPOINTS
    ENDPOINTS[url] = wrapper

    return wrapper

  return decorator
1178842
def _get_range(self, endpoint, *args, method='GET', **kwargs):
        
        if args:
            url = self.build_url(self._endpoints.get(endpoint).format(*args))
        else:
            url = self.build_url(self._endpoints.get(endpoint))
        if not kwargs:
            kwargs = None
        if method == 'GET':
            response = self.session.get(url, params=kwargs)
        elif method == 'POST':
            response = self.session.post(url, data=kwargs)
        if not response:
            return None
        return self.__class__(parent=self, **{self._cloud_data_key: response.json()})
970695
def _api_get(self):
        
        json = self._client.get(type(self).api_endpoint, model=self)
        self._populate(json)
582970
def do_get(self, line):
        

        def f(p, args):
            print(p.get())

        self._request(line, f)
822127
function get(url, shouldParse, callback) {
    request(url, function (err, response, body) {
        if (err) {
            console.error('Error making GET request to endpoint ' + url);
      callback(shouldParse ? {} : "{}");
        }

        if (response.statusCode !== 200) {
            console.error('non 200 response for URL: ' + url);
            callback(shouldParse ? {} : "{}");
            return;
        }

        var toReturn = shouldParse ? JSON.parse(body) : body;
        callback(toReturn);
        return;
    });
}
902085
def _request(self, action='GET', url='/', data=None, query_params=None):
        
        if data is None:
            data = {}
        if query_params is None:
            query_params = {}
        response = self.session.request(action, self.api[self.account]['endpoint'] + url,
                                        params=query_params, data=data)
        response.raise_for_status()
        return response
33960
function getURL(at, api_url, opts) {
  var params = "?token=" + at;
  if (opts)
    params = params + "&" + querystring.stringify(opts);
  return Constants.API_BASEURL + api_url + params;
}
768300
def get(self, data_type, options=None):
        
        if options is None:
            options = {}
        response = self._client.session.get(
            '{url}/{type}'.format(
                url=self.endpoint_url, type=data_type
            ),
            params=options
        )
        return self.process_response(response)
229473
def get_payload(self):
        
        temp = self.get_uri_as_list()
        query_string = temp[4]
        if query_string == "":
            return None  # Bad request error code
        query_string_as_list = str.split(query_string, "=")
        return query_string_as_list[1]
408444
def _get(self, uri, options):
        
        url = "http://%s/%s" % (self.host, uri)
        r = requests.get(url, params=options)
        if r.status_code == 200:
            data = r.json()
            return data['results']
        else:
            # Throws anything not 200 error
            r.raise_for_status()
304891
def get(self, params=None):
        
        return self._call('get', url=self.endpoint, params=params)
290823
def json_request(endpoint, verb='GET', session_options=None, **options):
    
    req = functools.partial(_request, endpoint, verb, session_options,
                            json=True, **options)
    return _run_in_fresh_loop(req)
140644
def request(self, method, endpoint, body=None, timeout=-1):
        
        if method not in set(['GET', 'POST', 'PUT', 'DELETE']):
            raise Exception('Invalid/Forbidden HTTP method')

        url = '/' + self.api_v + endpoint
        headers = {
            'Authorization': self.token,
            'Content-Type': 'application/json'
        }

        if body:
            json_body_or_None = json.dumps(body)
        else:
            json_body_or_None = None

        call_timeout = timeout if timeout != -1 else self.timeout

        APIcall = getattr(requests, method.lower())
        res = APIcall('https://api.upcloud.com' + url,
                      data=json_body_or_None,
                      headers=headers,
                      timeout=call_timeout)

        if res.text:
            res_json = res.json()
        else:
            res_json = {}

        return self.__error_middleware(res, res_json)