We don't manually write Typescript http-clients, instead we autogenerate them (not only Typescript, but C# http-clients as well). You should manually regenerate the clients when you add/update controllers/actions public interface.
If you are changing backend API and would like to update the client:
- Run your backend (usually via F5 in your IDE)
- From root folder run
yarn generate-api-clients
.
If you do not run backend locally, but your typescript client seems outdated, you could regenerate the client using remote backend
- From root folder run
yarn generate-api-clients-remote
(make sure you have specified correct remote URL in package.json, "generate-api-client-remote" script).
- Run
GenerateHttpClient_ValidAndExported
auto test (from BasicApiTests.cs)
Right now we post-process generated Typescript client, in order to provide correct types. We do the following modifications:
-
In ResponseDtos we change:
titleId!: number | undefined;
->titleId!: number | null;
We do this because in reality server sends usnull
, notundefined
. -
In Request (HTTP PATCH) DTO we change how
DateTime
is handled:data["start"] = this.start ? this.start.toISOString() : <any>undefined;
->data["start"] = this.start ? this.start.toISOString() : this.start;
We do this because it's otherwise impossible to pass bothnull
andundefined
to server. Here's the NSwag issue: RicoSuter/NJsonSchema#1239