Nswag: Plans for supporting the new Angular2 HttpClient

Created on 9 Aug 2017  路  9Comments  路  Source: RicoSuter/NSwag

Are there any plans on supporting the new Angular2 HttpClient, introduced in Angular2 4.3.0 (2017-07-14), by the ng2 typescript client?

Preview of the new HttpClient API :

HttpClient is an evolution of the existing Angular HTTP API, which exists
alongside of it in a separate package, @angular/common/http. This structure
ensures that existing codebases can slowly migrate to the new API.

The new API improves significantly on the ergonomics and features of the legacy
API. A partial list of new features includes:

  • Typed, synchronous response body access, including support for JSON body types
  • JSON is an assumed default and no longer needs to be explicitly parsed
  • Interceptors allow middleware logic to be inserted into the pipeline
  • Immutable request/response objects
  • Progress events for both request upload and response download
  • Post-request verification & flush based testing framework
NSwag.CodeGeneration.TypeScript enhancement

Most helpful comment

++1 for this change. As far as I know the changes predominantly involve moving to @ng/common/http from @ng/http. Since the newer module assumes all responses as JSON, it means the template needs to get rid of / change the .flatMap method a bit.

The basic functional change would be just to move to the newer objects in the other library. That shouldn't be very complex. However, moving to the new construct opens up tons up tuning options especially related to interceptors, HttpCache etc. Really interesting.

Note: It might be a breaking change for users on ng < 4.3.0

Http Official Docs

All 9 comments

Its not planned right now by myself. Maybe one of my customers is interested in this - otherwise it will not be implemented soon (its not that the old API is gone).

Are there many changes (new template) or can we just enhance the existing template?

++1 for this change. As far as I know the changes predominantly involve moving to @ng/common/http from @ng/http. Since the newer module assumes all responses as JSON, it means the template needs to get rid of / change the .flatMap method a bit.

The basic functional change would be just to move to the newer objects in the other library. That shouldn't be very complex. However, moving to the new construct opens up tons up tuning options especially related to interceptors, HttpCache etc. Really interesting.

Note: It might be a breaking change for users on ng < 4.3.0

Http Official Docs

It should be an option for the existing Angular template then.

The docs have been updated: https://github.com/RSuter/NSwag/wiki/SwaggerToTypeScriptClientGenerator#angular

Test with CI builds: https://ci.appveyor.com/project/rsuter/nswag-25x6o

Please report any problems, suggestions, etc. thank you.

@RSuter Great! Will do & lyk if there鈥檚 anything off. Cheers!

image

Thanks -a- lot!

@RSuter Excellent work on this! So far all looks great! I noticed we are using 'BLOB' response type to make the XHR calls. Can we switch to using ArrayBuffer instead (for non-file calls)? I have done some comparative analysis & they seem faster than blobs. Converting them back to actual form is simple as well..

Few links:
ArrayBuffer to String / String to ArrayBuffer
Array Buffer & Transferable Objects

Thoughts please?

Side note: I make all my rest calls in web workers hence the array buffer/transferable objects concept is a huge perf boost..

Was this page helpful?
0 / 5 - 0 ratings