apiConnectorCore 1.0.15

There is a newer version of this package available.
See the version list below for details.
dotnet add package apiConnectorCore --version 1.0.15
                    
NuGet\Install-Package apiConnectorCore -Version 1.0.15
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="apiConnectorCore" Version="1.0.15" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="apiConnectorCore" Version="1.0.15" />
                    
Directory.Packages.props
<PackageReference Include="apiConnectorCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add apiConnectorCore --version 1.0.15
                    
#r "nuget: apiConnectorCore, 1.0.15"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package apiConnectorCore@1.0.15
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=apiConnectorCore&version=1.0.15
                    
Install as a Cake Addin
#tool nuget:?package=apiConnectorCore&version=1.0.15
                    
Install as a Cake Tool

apiConnectorCore

Overview

The apiConnectorCore package is the .NET Core compatible successor to the legacy connector. It wraps authenticated HTTP requests against Net3000 APIs, supports typed responses, and includes asynchronous error forwarding that works with ASP.NET Core middleware and dependency injection.

Public API

<details> <summary>net3000.apiConnector</summary>

Member Summary Parameters
Task PostErrorDetailAsync(IExceptionHandlerPathFeature exceptionHandlerPathFeature, HttpContext context, string? customMessage) Post Error Detail Async. exceptionHandlerPathFeature (IExceptionHandlerPathFeature), context (HttpContext), customMessage (string?)
string getRawResponse(string url) Get Raw Response. url (string)
apiResponse getRequest(string url) Get Request. url (string)

</details>

Usage Notes

  • Set the configuration and myContext properties so that account headers and tokens are injected before calling getRequest.
  • Use the generic overload getRequest<T> when a typed API response is required.
  • PostErrorDetailAsync can be plugged into ASP.NET Core exception handlers to mirror legacy error logging behaviour.

Choosing the tenant from the URL (1.0.12+)

?accounttoken=, ?token= and ?account= select the tenant only on hosts that do not pin one. A site that sets account or accountToken (in AppSettings or in code) before the first myContext assignment keeps that tenant whatever the URL says. A host that pins a default tenant but serves other tenants by URL (views, DemoApplications) opts in:

"AppSettings": { "account": 4885, "acceptQueryAccountToken": true }

or connector.acceptQueryAccountToken = true in code.

Public CMS language

When myContext carries an explicit visitor ?lang=, GET reads under cm/ on the configured API forward its normalized value. Existing account/token selectors, caller-supplied lang, other APIs, and reads without a visitor language keep their URLs. The API's Content-Language on a resolved page/category is recorded in HttpContext.Items[CmsLanguageRequest.ItemKey]; layout menu/banner fallbacks do not override it. Accounts and views use CmsLanguageRequest.HtmlTag to put that resolved language and direction on the server-rendered opening HTML tag while retaining theme attributes. Standalone sites consuming the NuGet package need a package upgrade and the same layout call to adopt that document metadata; this change does not publish a package or update sibling repositories.

When the api is down (1.0.10+)

Register the outage filter once so an api outage shows a 503 "temporarily unavailable" page instead of a 500:

builder.Services.AddControllersWithViews(options => options.Filters.Add<ApiOutageFilter>());
  • A call that gets no response (refused, DNS, TLS, or the 30-second timeout) throws ApiUnavailableException.
  • A 3xx the client gave up following, or a 5xx that is not a tenant suspension, sets connector.ApiUnavailable.
  • Either one is recorded on myContext, so set connector.myContext = HttpContext before calling the api.
  • With the filter registered, an action that throws, a view whose model is a failed apiResponse, or a view that throws during that request all get ApiOutage.RenderPage (503, Retry-After: 120, no api call).
  • A site's own message() can return connector.ServiceUnavailablePage() when connector.ApiUnavailable is true.

The outage page (1.0.11+)

Every site serves the same page, https://cdn.net3000.ca/themes/platform/outage.html (ApiOutage.PageUrl). It is fetched with a 3-second timeout and cached for an hour; when the CDN cannot be reached the embedded copy (Resources/outage.html) is served instead.

To change the page, edit Resources/outage.html and upload the same file:

az storage blob upload --account-name net3000cdn --container-name themes --name platform/outage.html \
  --file "Class Libraries/apiConnectorCore/Resources/outage.html" --content-type "text/html; charset=utf-8" \
  --content-cache-control "public, max-age=300" --overwrite --auth-mode key

Sites pick it up within an hour, with no release. Ship the edited file in the next package version too, so the fallback matches.

AppSettings:apiUrl must be the origin the api answers on (1.0.15+)

A response that comes back from a different origin than the request was sent to throws ApiConfigurationException, on every verb. AppSettings:apiUrl must therefore be the origin the api actually answers on — https://api.net3000.ca/ live, https://api.net3000.co/ staging — not a form of it that the api redirects away from.

Why it fails rather than being followed (#8159): the connector follows redirects, and .NET downgrades a POST to a GET when it follows a 301 or 302. The api serves no GET for a write route, so it answers that GET from /message/404 and the typed client's contract check fires, telling the site to upgrade its package over a one-line configuration fault. A GET survives the redirect unchanged, so the catalog renders, the site looks healthy, and only the write fails. Verified against staging: POST http://api.net3000.co/cm/processform arrived as a GET at https://api.net3000.co/message/404, while GET http://api.net3000.co/cm/pages returned 24 rows.

Three shapes of apiUrl are caught — http for an https api, an apex host for a www one (or the reverse), and a CDN or proxy hostname in front of the api. The exception names AnsweredByOrigin, which is the value apiUrl should hold, and says plainly that the fix is configuration rather than a package upgrade.

Same-origin redirects still pass, and that is load-bearing: the api redirects a bodyless 4xx to its own /message/{code} page, so an unknown route lands on /message/404 and a login-gated route on /message/401, both of which the caller reads.

A route whose own answer is an off-origin redirect — GET /cm/banners/click sends the visitor to the slide's target site, POST /cm/processformbyaction to a configured thank-you page — opts out per call. No typed client package wraps either.

connector.allowOffOriginResponse = true;
try { html = connector.getRawResponse("cm/banners/click?id=" + id); }
finally { connector.allowOffOriginResponse = false; }

The contract guard for typed client packages (1.0.15+)

ApiContract is the check the net3000.*.client packages call after every wrapped JSON route, and it lives here rather than in each package: it was hand-copied into sixteen of them, and both of its defects therefore reached eleven packages apiece (#8152).

var response = connector.getRequest<cm_content>("cm/content?code=" + code);
ApiContract.Guard(connector, "GET", "cm/content?code=" + code,
    "net3000.content.client", CmContractVersion, PackageVersion);

It throws ApiContractException when the api does not serve the route: the status is 404 or 405, or the response was answered from the api's own /message/404 or /message/405 page instead of the url asked for. Two signals, because an unknown route does not answer 404 — api/Program.cs ends with UseStatusCodePagesWithRedirects("/message/{0}"), so it is redirected to /message/404, which answers HTTP 200 and a success = true "Page Not Found" envelope that a typed read turns into an ordinary success = false response, indistinguishable from a tenant with no content.

Two rules in it are the corrected ones, and neither is optional:

  • Only /message/404 and /message/405 count, never "any redirect". Those two say the api does not serve the route — an unknown path, and a path that exists for other verbs but not this one — and neither can be a route's own reply to a caller that asked correctly. That same middleware redirects every bodyless 4xx, so a login-gated route answers an unauthenticated caller with a 302 to /message/401 — and the any-redirect rule threw on routes the api serves (GET /mt/affiliates/packages). An auth refusal is an answer.
  • Compare AbsolutePath, never GetLeftPart(UriPartial.Path), which brings the scheme and authority with it and made every call throw once the configured host differed from the answering one. An apiUrl the api redirects away from is a real fault of a different kind, caught at the transport (above) rather than reported as contract drift.

ApiContract.GuardSurface is the strict twin, for a surface probe only: it treats any other answering path as drift, not just a contract-mismatch page. That is sound only on a route whose every code path returns an apiResponse, so it cannot produce a bodyless status and a redirect can only mean the surface is absent — faq's GET /faq/published and sc's GET /sc/settings, behind their VerifyContract(). Never reach for it per call.

ApiContract.SamePath and ApiContract.IsContractMismatchPage are public for the raw and binary helpers, which report the redirect signal on their own response type instead of throwing on it. One ApiContractException serves every package; PackageId, ContractVersion and PackageVersion carry what a per-package exception type used to say.

License

This library is proprietary to Net3000. Redistribution or use outside Net3000.ca solutions is not permitted.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on apiConnectorCore:

Package Downloads
net3000.mailingList

Mailing list management library for Net3000.ca applications. Subscriber management, campaigns, multi-platform integrations (SendGrid, MailChimp, Constant Contact), delivery tracking, and audience contact sources.

net3000.content.client

Typed client for the Content Management (cm) routes on api.net3000.ca. One method per live /cm/ route, returning the same apiResponse<T> models the api serialises, over the apiConnectorCore transport. A client website reads CMS pages, categories, menus, banners, videos, forms and testimonials with no database connection string.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.16 91 11/29/2026
1.0.15 92 11/29/2026
1.0.14 85 11/28/2026
1.0.12 206 10/29/2026
1.0.5 301 7/8/2026
1.0.4 180 7/4/2026
1.0.3 259 1/4/2026
1.0.1 376 7/15/2025
1.0.0.9 314 7/15/2025
1.0.0.8 317 7/15/2025
1.0.0.7 358 4/10/2025
1.0.0.6 359 4/9/2025
1.0.0.5 670 3/25/2025
1.0.0.4 667 3/25/2025
1.0.0.3 415 7/17/2023
1.0.0.2 734 4/14/2022
1.0.0.1 631 3/20/2022

1.0.15: The typed client packages' contract guard, landed once, and a redirecting apiUrl now fails the request (#8152, #8159, epic #8079). ApiContract.Guard / SamePath / IsNotFoundPage / Requested replace the GuardContract and SamePath helpers each of the sixteen net3000.*.client packages hand-copied, which is how both of their defects reached eleven packages apiece: an any-redirect rule that threw on a login-gated route's own 302 to /message/401, and a path comparison over GetLeftPart(UriPartial.Path) that threw on every call once the scheme or host differed. The shared guard treats as drift only a 404/405, or a redirect landing on /message/404 or /message/405 - the two pages that say the api does not serve the route, and the pair md and msq already keyed on - and compares AbsolutePath. ApiContract.GuardSurface is the strict twin for a surface probe, where any answering path other than the one asked for is drift; sound only on a route that cannot answer a bodyless status, which is what faq and sc each built their VerifyContract() probe on. One ApiContractException serves every package, carrying PackageId, ContractVersion, PackageVersion, the method, the requested url, the status and the answering url; sixteen identical per-app exception types were the same duplication, and nothing handled them differently. BREAKING, by decision: a response that comes back from a different origin than the request was sent to now throws ApiConfigurationException, on every verb, instead of being accepted. apiConnector follows redirects and .NET downgrades a POST to a GET when it does, so an AppSettings:apiUrl the api redirects away from (http for an https api, an apex host for a www one, a CDN hostname in front of it) turned every write into a GET the api does not serve while reads kept working, so the site looked healthy and only checkout failed. The exception names the origin that answered, which is the value apiUrl should hold, and says the fix is configuration rather than a package upgrade. A site configured with a non-canonical apiUrl now stops working at deploy instead of failing silently at the first write; that is the accepted trade. apiConnector.allowOffOriginResponse opts a single call out, for the two api routes whose own answer is an off-origin redirect (GET /cm/banners/click, POST /cm/processformbyaction); no client package wraps either. 1.0.14: The shared transport the typed client packages need, landed once (#8126, epic #8079). bearerToken sends a signed-in end user's JWT as Authorization: Bearer on every call, so the routes that answer for a signed-in client (the limo client portal, the corporate portal, the app checkout) are reachable from a client package without a second HTTP pipeline; tenant selection is unchanged and a caller that sets nothing sends no Authorization header. deleteRequest<T> / deleteRequest send a DELETE with no body, for the portal routes that delete by URL. sendRequest / sendRequest<T> send a body with any HTTP method, because a route only answers the verb it is declared with and the Almotawif surface has PUT /mt/reservation; use deleteRequest for a bodyless DELETE and sendRequest when a non-POST verb carries a body. postRawResponse is the POST twin of getRawResponse, for a write route that answers HTML, a redirect or a bare string rather than an apiResponse envelope. A non-generic postFilesRequest covers an upload route that answers a bare apiResponse with no data (deserialising such a reply as apiResponse<T> and handing it back as apiResponse reads data off the base class, which the generic subclass shadows, so it is always null). All of it reuses the existing tenant headers, outage detection and apiResponse deserialiser. Additive. Landed as one release rather than three because #8107, #8108 and #8110 each added an overlapping subset and all three claimed 1.0.14, so merging any two would have declared deleteRequest or postRawResponse twice. 1.0.13: Write and binary transport for the typed client packages (#8080, epic #8079). postRequest<T> / postRequest POST a JSON body, postFilesRequest<T> posts multipart/form-data, and getBytesResponse GETs a file without corrupting it through a string. All four reuse the existing tenant headers, outage detection and apiResponse deserialisation, so a client package never stands up an HttpClient of its own. A POST that gets no response throws ApiUnavailableException like a GET, instead of returning the exception message as if it were a body (the pre-existing postform did). LastContentType reports the last binary reply's type, and postFile gains an optional contentType. Additive. 1.0.12: Security (#5554): a site that pins its own tenant (account or accountToken set before myContext) no longer lets ?accounttoken=, ?token= or ?account= in the URL replace it, which since 1.0.6 let a shared link render another tenant's content on a customer domain and made unrelated ?token= links (login verify, device confirm) break api calls. Hosts that pin a default tenant but serve others by URL opt in with AppSettings:acceptQueryAccountToken=true (views, DemoApplications) or apiConnector.acceptQueryAccountToken. Hosts that pin nothing (iframes, accounts) are unchanged. 1.0.11: The outage page is one file on the CDN (https://cdn.net3000.ca/themes/platform/outage.html), fetched with a 3-second timeout and cached for an hour, so its copy can change without a release; the same file is embedded as the fallback. The card is centred vertically. ApiOutage.UnavailableHtml is replaced by PageHtml() / FallbackHtml. 1.0.10: Api outage handling for customer sites (#5554). ApiOutageFilter (register once) serves a 503 page with Retry-After when the api is down instead of a 500; apiConnector.ApiUnavailable and ServiceUnavailablePage(); a call that gets no response now throws ApiUnavailableException (was a nested AggregateException) and resets LastHttpStatusCode to 0; api requests time out after 30 seconds instead of 100. 1.0.9: Preserve a public tenant selector on shared sign-in/sign-up redirects as well as returnUrl (#5299), so fresh Business Directory sessions select the right account; SignUpUrlFromAuthQuery / SignInUrlFromAuthQuery keep the auth page's own tenant on the sign-in/sign-up cross-links. 1.0.8: Account suspension rendering for customer SSR sites (issue #3029 Part 3). postForm and apiConnector expose LastHttpStatusCode; AccountSuspension detects HTTP 503 / notActive (401) and renders the platform page with Retry-After and Cache-Control no-store; FetchSuspensionHtml pulls copy from GET /common/suspension with a hardcoded fallback. 1.0.7: Move AccountAreaPage, AccountClientPortalAttribute, and AccountPublicAuthAttribute into apiConnectorCore so customer sites have shared /account/* portal defaults without code duplication. 1.0.6: getRequest / getRequest<T> never return null when the API body is empty or JSON null — keep a seeded invalid apiResponse (success=false) so callers that touch response.success do not 500. 1.0.5: Error-reporting hardening + one-line wiring.