zijianhuang / webapiclientgen

Strongly Typed Client API Generators generate strongly typed client APIs in C# .NET and in TypeScript for jQuery and Angular 2+ from ASP.NET Web API and .NET Core Web API
MIT License
167 stars 38 forks source link

handling stream in ng codes #45

Closed zijianhuang closed 6 years ago

zijianhuang commented 6 years ago
        [HttpGet]
        [Route("TextStream")]
        public HttpResponseMessage GetTextStream()
        {
            var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("abcdefg"));
            {
                var content = new StreamContent(stream);
                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
                return new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = content
                };
            }
        }

        /**
         * GET api/SuperDemo/TextStream
         */
      getTextStream(): Observable<HttpResponse<Blob>> {
        return this.http.get(this.baseUri + 'api/SuperDemo/TextStream', { observe: 'response', responseType: 'blob' });
        }
zijianhuang commented 6 years ago

The same for

        [HttpGet]
        [Route("ActionResult")]
        public IHttpActionResult GetActionResult()
        {
            return Ok("abcdefg");
        }
zijianhuang commented 6 years ago

similar things could hardly be done for jQuery. I may have to write my own HttpClient similar to what in NG2.

zijianhuang commented 6 years ago

all done