Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Export HttpClient class and publish version 3.4.0 #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<VersionPrefix>3.3.0</VersionPrefix>
<PackageValidationBaselineVersion>3.1.0</PackageValidationBaselineVersion>
<VersionPrefix>3.4.0</VersionPrefix>
<PackageValidationBaselineVersion>3.3.0</PackageValidationBaselineVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

These are the NuGet package releases. See also [npm Release Notes](ReleaseNotesNpm.md).

## 3.4.0

* Export generated HttpClient class, allowing the class to be extended.

## 3.3.0

* Allow for request scoped services in fastify plugin.
Expand Down
9 changes: 5 additions & 4 deletions conformance/src/conformanceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { IConformanceApi, IGetApiInfoRequest, IGetApiInfoResponse, IGetWidgetsRe
export * from './conformanceApiTypes';

/** Provides access to ConformanceApi over HTTP via fetch. */
export function createHttpClient({ fetch, baseUri }: IHttpClientOptions): IConformanceApi {
return new ConformanceApiHttpClient(fetch, baseUri);
export function createHttpClient(options: IHttpClientOptions): IConformanceApi {
return new ConformanceApiHttpClient(options);
}

const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;
Expand All @@ -27,8 +27,9 @@ function parseBoolean(value: string | undefined) {
return undefined;
}

class ConformanceApiHttpClient implements IConformanceApi {
constructor(fetch: IFetch, baseUri?: string) {
/** Provides access to ConformanceApi over HTTP via fetch. */
export class ConformanceApiHttpClient implements IConformanceApi {
constructor({ fetch, baseUri }: IHttpClientOptions) {
if (typeof fetch !== 'function') {
throw new TypeError('fetch must be a function.');
}
Expand Down
9 changes: 5 additions & 4 deletions conformance/src/jsConformanceApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { HttpClientUtility } from 'facility-core';

/** Provides access to JsConformanceApi over HTTP via fetch. */
export function createHttpClient({ fetch, baseUri }) {
return new JsConformanceApiHttpClient(fetch, baseUri);
export function createHttpClient(options) {
return new JsConformanceApiHttpClient(options);
}

const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;
Expand All @@ -24,8 +24,9 @@ function parseBoolean(value) {
return undefined;
}

class JsConformanceApiHttpClient {
constructor(fetch, baseUri) {
/** Provides access to JsConformanceApi over HTTP via fetch. */
export class JsConformanceApiHttpClient {
constructor({ fetch, baseUri }) {
if (typeof fetch !== 'function') {
throw new TypeError('fetch must be a function.');
}
Expand Down
9 changes: 5 additions & 4 deletions example/js/exampleApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import { HttpClientUtility } from 'facility-core';

/** Provides access to ExampleApi over HTTP via fetch. */
export function createHttpClient({ fetch, baseUri }) {
return new ExampleApiHttpClient(fetch, baseUri);
export function createHttpClient(options) {
return new ExampleApiHttpClient(options);
}

const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;

class ExampleApiHttpClient {
constructor(fetch, baseUri) {
/** Provides access to ExampleApi over HTTP via fetch. */
export class ExampleApiHttpClient {
constructor({ fetch, baseUri }) {
if (typeof fetch !== 'function') {
throw new TypeError('fetch must be a function.');
}
Expand Down
9 changes: 5 additions & 4 deletions example/ts/src/exampleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { IExampleApi, IGetWidgetsRequest, IGetWidgetsResponse, ICreateWidgetRequ
export * from './exampleApiTypes';

/** Provides access to ExampleApi over HTTP via fetch. */
export function createHttpClient({ fetch, baseUri }: IHttpClientOptions): IExampleApi {
return new ExampleApiHttpClient(fetch, baseUri);
export function createHttpClient(options: IHttpClientOptions): IExampleApi {
return new ExampleApiHttpClient(options);
}

const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;
type IFetch = HttpClientUtility.IFetch;
type IFetchRequest = HttpClientUtility.IFetchRequest;

class ExampleApiHttpClient implements IExampleApi {
constructor(fetch: IFetch, baseUri?: string) {
/** Provides access to ExampleApi over HTTP via fetch. */
export class ExampleApiHttpClient implements IExampleApi {
constructor({ fetch, baseUri }: IHttpClientOptions) {
if (typeof fetch !== 'function') {
throw new TypeError('fetch must be a function.');
}
Expand Down
9 changes: 5 additions & 4 deletions src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public override CodeGenOutput GenerateOutput(ServiceInfo service)

code.WriteLine();
WriteJsDoc(code, $"Provides access to {capModuleName} over HTTP via fetch.");
using (code.Block("export function createHttpClient({ fetch, baseUri }" + IfTypeScript(": IHttpClientOptions") + ")" + IfTypeScript($": I{capModuleName}") + " {", "}"))
code.WriteLine($"return new {capModuleName}HttpClient(fetch, baseUri);");
using (code.Block("export function createHttpClient(options" + IfTypeScript(": IHttpClientOptions") + ")" + IfTypeScript($": I{capModuleName}") + " {", "}"))
code.WriteLine($"return new {capModuleName}HttpClient(options);");

code.WriteLine();
code.WriteLine("const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;");
Expand Down Expand Up @@ -192,9 +192,10 @@ public override CodeGenOutput GenerateOutput(ServiceInfo service)
}

code.WriteLine();
using (code.Block($"class {capModuleName}HttpClient" + IfTypeScript($" implements I{capModuleName}") + " {", "}"))
WriteJsDoc(code, $"Provides access to {capModuleName} over HTTP via fetch.");
using (code.Block($"export class {capModuleName}HttpClient" + IfTypeScript($" implements I{capModuleName}") + " {", "}"))
{
using (code.Block("constructor(fetch" + IfTypeScript(": IFetch") + ", baseUri" + IfTypeScript("?: string") + ") {", "}"))
using (code.Block("constructor({ fetch, baseUri }" + IfTypeScript(": IHttpClientOptions") + ") {", "}"))
{
using (code.Block("if (typeof fetch !== 'function') {", "}"))
code.WriteLine("throw new TypeError('fetch must be a function.');");
Expand Down