Generate a view for the specified method and endpoint.

        :param method: HTTP Method
        :param endpoint: Pattern
496522
def _generate_view(self, method, endpoint):
        

        def new_view(**kwargs):
            if method == Method.GET:
                data = request.args
            else:
                content_length = request.headers.get('content-length', 0)
                if content_length and int(content_length) > 0:
                    content_type = request.headers.get('content-type', None)
                    if content_type != 'application/vnd.api+json':
                        data = MissingContentTypeError().data
                        data = json.dumps(data, cls=JSONAPIEncoder)
                        response = make_response(data)
                        response.status_code = 409
                        response.content_type = 'application/vnd.api+json'
                        return response
                    data = request.get_json(force=True)
                else:
                    data = None

            event_kwargs = {
                'method': method,
                'endpoint': endpoint,
                'data': data,
                'req_args': kwargs
            }
            results = self.on_request.send(self, **event_kwargs)
            data = override(data, results)

            args = [self.sqla.session, data, kwargs['api_type']]
            if 'obj_id' in kwargs.keys():
                args.append(kwargs['obj_id'])
            if 'relationship' in kwargs.keys():
                args.append(kwargs['relationship'])

            try:
                attr = '{}_{}'.format(method.name, endpoint.name).lower()
                handler = getattr(self.serializer, attr)
                handler_chain = list(self._handler_chains.get((
                    kwargs['api_type'], method, endpoint), []))
                handler_chain.append(handler)
                chained_handler = self._call_next(handler_chain)
                response = chained_handler(*args)
                results = self.on_success.send(self,
                                               response=response,
                                               **event_kwargs)
                response = override(response, results)
            except BaseError as exc:
                self.sqla.session.rollback()
                results = self.on_error.send(self, error=exc, **event_kwargs)
                response = override(exc, results)
            rendered_response = make_response('')
            if response.status_code != 204:
                data = json.dumps(response.data, cls=self.json_encoder)
                rendered_response = make_response(data)
            rendered_response.status_code = response.status_code
            rendered_response.content_type = 'application/vnd.api+json'
            results = self.on_response.send(self,
                                            response=rendered_response,
                                            **event_kwargs)
            return override(rendered_response, results)

        return new_view
421297
def from_view(cls, view, *methods, name=None):
        """"""
        docs = getattr(view, '__doc__', None)
        view = to_coroutine(view)
        methods = methods or ['GET']

        if METH_ANY in methods:
            methods = METH_ALL

        def proxy(self, *args, **kwargs):
            return view(*args, **kwargs)

        params = {m.lower(): proxy for m in methods}
        params['methods'] = methods
        if docs:
            params['__doc__'] = docs

        return type(name or view.__name__, (cls,), params)
1289418
def show_form_for_method(self, view, method, request, obj):
        
        if method not in view.allowed_methods:
            return  # Not a valid method

        try:
            view.check_permissions(request)
            if obj is not None:
                view.check_object_permissions(request, obj)
        except exceptions.APIException:
            return False  # Doesn't have permissions
        return True
910804
def add_filter(self, methods=None, endpoints=None):
        
        if not methods and not endpoints:
            raise ValueError('Filter cannot be added with no criteria.')

        filter = TraceFilter(methods, endpoints)
        self.filters.append(filter)
        return filter
1127348
def view_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/views.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
1177189
def service_endpoint url
      endpoint = LIST.find do |(pattern, endpoint)|
        url =~ pattern
      end
      endpoint ? endpoint.last : false
    end
181886
def expose_endpoint(self):
        
        @self._app.route('/metrics', methods=['GET'])
        async def expose_metrics(request):
            return raw(self._get_metrics_data(),
                       content_type=CONTENT_TYPE_LATEST)
820060
function (method, endpoint, routerMiddelware) {
		var self = this;

		if (typeof routerMiddelware == 'object'){
			this.app[method](endpoint, function (req, res, next) {
				var middlewareFunction = []
				routerMiddelware.forEach(function (m) {
					middlewareFunction.push(function (cb) {
						self.__exec__middlewares(m, req, res, cb);
					});
				});

				async.waterfall(middlewareFunction);
			});
		} else {
			this.app[method](endpoint, function (req, res, next) {
				self.__exec__middleware(routerMiddelware)(req, res, next);
			});
		}
	}
79507
def do_request method, endpoint, data = {}
      url = get_url(endpoint, method)
      options = {
        format: :json
      }

      # Allow custom HTTParty args.
      options = options.merge(@httparty_args)

      # Set headers.
      options[:headers] = {
        "User-Agent" => "WooCommerce API Client-Ruby/#{WooCommerce::VERSION}",
        "Accept" => "application/json"
      }
      options[:headers]["Content-Type"] = "application/json;charset=utf-8" if !data.empty?

      # Set basic authentication.
      if @is_ssl
        options[:verify] = @verify_ssl

        if @query_string_auth
          options.merge!(query: {
            consumer_key: @consumer_key,
            consumer_secret: @consumer_secret
          })
        else
          options.merge!(basic_auth: {
            username: @consumer_key,
            password: @consumer_secret
          })
        end
      end

      options.merge!(debug_output: $stdout) if @debug_mode
      options.merge!(body: data.to_json) if !data.empty?

      HTTParty.send(method, url, options)
    end
147394
def call(self, name, request=None, **params):
        
        if name not in self.resources:
            raise exceptions.HttpError(
                'Unknown method \'%s\'' % name,
                status=status.HTTP_501_NOT_IMPLEMENTED)
        request = request or HttpRequest()
        resource = self.resources[name]
        view = resource.as_view(api=self)
        return view(request, **params)
784099
def endpoint(self):
        
        if self._endpoint:
            return self._endpoint
        elif self._controller_cls:
            endpoint = f'{snake_case(self._controller_cls.__name__)}.{self.method_name}'
            return endpoint if not self.bp_name else f'{self.bp_name}.{endpoint}'
        elif self.bp_name:
            return f'{self.bp_name}.{self.method_name}'
        return f'{self.view_func.__module__}.{self.method_name}'
1035895
def _match_view(self, method, route_params):
        
        method = method.upper()
        route_params = frozenset(k for k, v in route_params.items() if v is not None)

        for view_name, info in self.methods_map[method].items():
            if info.matches(method, route_params):
                return getattr(self, view_name)
        else:
            return None
1130899
def view_for(self, action='view'):
        
        app = current_app._get_current_object()
        view, attr = self.view_for_endpoints[app][action]
        return getattr(view(self), attr)
266848
def build_url(method, args)
        API::URL.new(method, config.base_url, args).path
      end
403453
protected function addEndpoint(EndpointCollection $endpoints, ReflectionClass $class,
                                   $method, array $annotations)
	{
		$endpoints->push($endpoint = new MethodEndpoint([
			'reflection' => $class, 'method' => $method, 'uses' => $class->name.'@'.$method
		]));

		foreach ($annotations as $annotation)
			$annotation->modify($endpoint, $class->getMethod($method));
	}
45668
void configureEndpoints(Reflections reflections) {

        // [Re]initialise the api:
        api = new HashMap<>();

        log.info("Scanning for endpoint classes..");
        Set<Class<?>> endpoints = reflections.getTypesAnnotatedWith(Api.class);
        // log.info(reflections.getConfiguration().getUrls());

        log.info("Found {} endpoint classes.", endpoints.size());
        log.info("Examining endpoint class methods:");

        // Configure the classes:
        for (Class<?> endpointClass : endpoints) {

            Route route = getEndpoint(endpointClass);
            route.endpointClass = endpointClass;

            for (Method method : endpointClass.getMethods()) {

                // Skip Object methods
                if (method.getDeclaringClass() == Object.class) {
                    continue;
                }

                // Find public methods:
                if (Modifier.isPublic(method.getModifiers())) {

                    // Which HTTP method(s) will this method respond to?
                    annotation:
                    for (Annotation annotation : method.getAnnotations()) {
                        HttpMethod httpMethod = HttpMethod.method(annotation);
                        if (httpMethod != null) {
                            log.info("Http method: {}", httpMethod);

                            RequestHandler requestHandler = new RequestHandler();
                            requestHandler.handlerMethod = method;
                            log.info("Java method: {}", method.getName());

                            // Look for an optional Json message type parameter:
                            for (Class<?> parameterType : method.getParameterTypes()) {
                                if (!HttpServletRequest.class.isAssignableFrom(parameterType)
                                        && !HttpServletResponse.class.isAssignableFrom(parameterType)) {
                                    if (requestHandler.requestMessageType != null) {
                                        log.error("Too many parameters on {} method {}. " +
                                                        "Message type already set to {} but also found a {} parameter.",
                                                httpMethod, method.getName(),
                                                requestHandler.requestMessageType.getSimpleName(), parameterType.getSimpleName());
                                        break annotation;
                                    }
                                    requestHandler.requestMessageType = parameterType;
                                    log.info("request Json: {}", requestHandler.requestMessageType.getSimpleName());
                                }
                            }

                            // Check the response Json message type:
                            if (method.getReturnType() != void.class) {
                                requestHandler.responseMessageType = method.getReturnType();
                                log.info("Response Json: {}", requestHandler.responseMessageType.getSimpleName());
                            }

                            route.requestHandlers.put(httpMethod, requestHandler);

                        }
                    }
                }
            }
        }

    }
1052470
def endpoint_response(code, type = nil, description = nil, headers = [])
      responses = settings.swagger_current_endpoint_responses
      check_if_not_duplicate(code, responses, 'Response')
      responses[code] = Sinatra::SwaggerExposer::Configuration::SwaggerEndpointResponse.new(
        type,
        description,
        settings.swagger_types.types_names,
        headers,
        settings.swagger_response_headers
      )
    end