Exemplo n.º 1
0
        public async Task <ResponseWithHeaders <string, SchemaGetByIdHeaders> > GetByIdAsync(string schemaId, CancellationToken cancellationToken = default)
        {
            if (schemaId == null)
            {
                throw new ArgumentNullException(nameof(schemaId));
            }

            using var message = CreateGetByIdRequest(schemaId);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new SchemaGetByIdHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                StreamReader streamReader = new StreamReader(message.Response.ContentStream);
                string       value        = await streamReader.ReadToEndAsync().ConfigureAwait(false);

                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public async Task <ResponseWithHeaders <string, SchemaGetByIdHeaders> > GetByIdAsync(string schemaId, CancellationToken cancellationToken = default)
        {
            if (schemaId == null)
            {
                throw new ArgumentNullException(nameof(schemaId));
            }

            using var message = CreateGetByIdRequest(schemaId);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new SchemaGetByIdHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                string value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = document.RootElement.GetString();
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }
Exemplo n.º 3
0
        public ResponseWithHeaders <Stream, SchemaGetByIdHeaders> GetById(string id, CancellationToken cancellationToken = default)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            using var message = CreateGetByIdRequest(id);
            _pipeline.Send(message, cancellationToken);
            var headers = new SchemaGetByIdHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                var value = message.ExtractResponseContent();
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }