示例#1
0
        public async Task <ServiceRestResponse <object> > ProxyRequest(ServiceProxyRequest request)
        {
            if (string.IsNullOrEmpty(request.ServiceName))
            {
                throw new ServiceNotFoundException(request.ServiceName);
            }

            var client = await ServiceRestApiClient.Create(request.ServiceName, _discovery);

            if (client == null)
            {
                throw new ServiceNotFoundException(request.ServiceName);
            }

            switch (request.Method.ToLowerInvariant())
            {
            case "get":
                return(await client.Get <object>($"{request.Url}{request.QueryString}"));

            case "post":
                return(await client.Post <object>($"{request.Url}{request.QueryString}", request.Body));

            case "put":
                return(await client.Put <object>($"{request.Url}{request.QueryString}", request.Body));

            /*case "patch":
             *  return await client.Patch<object>($"{request.Url}{request.QueryString}", request.Body);*/
            case "delete":
                return(await client.Delete <object>($"{request.Url}{request.QueryString}"));
            }

            return(null);
        }
        private async Task <ServiceRestApiClient> GetClient(string serviceName)
        {
            if (_clients.ContainsKey(serviceName))
            {
                return(_clients[serviceName]);
            }

            var client = await ServiceRestApiClient.Create(serviceName, _discovery);

            if (client != null)
            {
                _clients.Add(serviceName, client);
            }
            return(client);
        }